【发布时间】:2023-02-17 11:30:35
【问题描述】:
我正在尝试使用我在媒体上找到的一篇文章使用 python 创建一个 gmail 帐户。这是文章:https://betterprogramming.pub/creating-temporary-gmails-accounts-with-python-9c200c52ebb7
这是我的代码:
def generate_gmail(ID: int):
# access the API
url = "https://temp-gmail.p.rapidapi.com/get"
querystring = {"id":ID,"type":"alias"}
headers = {
'x-rapidapi-host': "temp-gmail.p.rapidapi.com",
'x-rapidapi-key': "YOUR PRIVATE KEY"
}
# send a request to the API
response = requests.request("GET", url, headers=headers, params=querystring)
# convert the response to JSON format
json_response = response.json()
# get gmail address
gmail = json_response['items']['username']
# get gmail password
password = json_response['items']['key']
print('Gmail address: %s' % str(gmail))
print('Password: %s' % str(password))
我已经输入了我的私钥。当我在终端中使用“python3 file_name.py”运行代码时,我没有收到电子邮件和密码的输出。我究竟做错了什么?
【问题讨论】:
-
您的代码只定义了一个函数,但没有调用它。
-
你确定你是按照那篇文章一步一步来的吗?您是否在“file_name.py”中的某处调用了 generate_gmail(ID=YOUR_ID)?