简体   繁体   English

gaierror: [Errno -2] Google Cloud Functions 中 imaplib.IMAP4_SSL 未知的名称或服务

[英]gaierror: [Errno -2] Name or service not known with imaplib.IMAP4_SSL in Google Cloud Functions

I have a perfectly fine script that works fine when I run it locally to authenticate using IMAP4_SSL and imaplib as follows:我有一个非常好的脚本,当我在本地运行它以使用 IMAP4_SSL 和imaplib进行身份验证时,它可以imaplib ,如下所示:

mail = imaplib.IMAP4_SSL(host_incoming, port_incoming)
mail.login(user, password)
mail.list()

However, when I host this part of the code in the Google Cloud Functions, then I receive the error:但是,当我在 Google Cloud Functions 中托管这部分代码时,我收到错误消息:

gaierror: [Errno -2] Name or service not known getaddrinfo (/opt/python3.7/lib/python3.7/socket.py) gaierror: [Errno -2] 名称或服务未知 getaddrinfo (/opt/python3.7/lib/python3.7/socket.py)

If I use Google Gmail credentials instead (for host, port, user and password), then no errors are provided and everything works fine.如果我改用 Google Gmail 凭据(用于主机、端口、用户和密码),则不会提供任何错误并且一切正常。 So what is wrong with the email or server that I am using and how could I check this?那么我使用的电子邮件或服务器有什么问题,我该如何检查呢?

Have you added a billing account for your the project containing your Cloud Function?您是否为包含 Cloud Functions 的项目添加了结算帐户? Functions on the free tier cannot communicate with external networks and will fail DNS lookup.免费层上的功能无法与外部网络通信,并且 DNS 查找将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM