我正在将Mailjet集成到我的Google App Engine应用程序中。我已经可以成功地从本地开发服务器发送电子邮件了。但是当我部署我的应用程序并尝试发送电子邮件时,Mailjet客户端库在尝试连接到Mailjet rest API时显然遇到了错误。
由NewConnectionError引起(‘:无法建立新连接: Errno -3名称解析暂时失败’
我基本上遵循了下面的说明
https://cloud.google.com/appengine/docs/standard/python/mail/sending-messages
和
https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
我为集成mailjet添加的代码。
requirements.txt:
certifi==2019.6.16
chardet==3.0.4
idna==2.8
mailjet-rest==1.3.3
requests==2.22.0
urllib3==1.25.3app.yaml:
...
libraries:
- name: ssl
version: latestmain.py:
from mailjet_rest import Client
...
#calling this function to send email
def mailjet_sendmail(to_address, subject, body):
api_key = '***'
api_secret = '***'
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
'Messages': [
{
"From": {
"Email": "noreply@mydomain.com",
"Name": "mydomain.com"
},
"To": [
{
"Email": to_address,
}
],
"Subject": subject,
"TextPart": body,
}
]
}
result = mailjet.send.create(data=data)当我调用mailjet.send.create时,错误日志中显示以下异常:
ApiError: HTTPSConnectionPool(host='api.eu.mailjet.com', port=443): Max retries exceeded with url: /v3.1/send (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x2a66ef5e1950>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
at api_call (/base/data/home/apps/s~***/20190828t114640.420634513089712020/mailjet_rest/client.py:110)
at create (/base/data/home/apps/s~***/20190828t114640.420634513089712020/mailjet_rest/client.py:62)
at mailjet_sendmail (/base/data/home/apps/s~***/20190828t114640.420634513089712020/main.py:80)
at post (/base/data/home/apps/s~***/20190828t114640.420634513089712020/main.py:379)
...看起来它似乎无法解析api.eu.mailjet.com。
我需要做什么才能在Google App Engine中启用DNS查找?有没有人能展示一个完整的工作示例?
请注意,完全相同的代码可以在运行本地开发服务器的PC上运行。
谢谢
弗雷德
发布于 2019-08-28 19:37:46
在进一步搜索之后,我实际上找到了我自己问题的答案。
唯一的问题是没有帐单帐户链接到该项目。对于其余的,一切都是正确的。
希望这对其他人有帮助。
弗雷德
https://stackoverflow.com/questions/57690568
复制相似问题