【问题标题】:gaierror: [Errno -2] Name or service not known with imaplib.IMAP4_SSL in Google Cloud Functionsgaierror:[Errno -2] Google Cloud Functions 中 imaplib.IMAP4_SSL 的名称或服务未知
【发布时间】:2019-07-26 00:37:23
【问题描述】:

我有一个完美的脚本,当我在本地运行它以使用 IMAP4_SSL 和 imaplib 进行身份验证时工作正常,如下所示:

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

但是,当我将这部分代码托管在 Google Cloud Functions 中时,我会收到错误消息:

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

如果我改用 Google Gmail 凭据(用于主机、端口、用户和密码),则不会提供任何错误并且一切正常。那么我使用的电子邮件或服务器有什么问题,我该如何检查呢?

【问题讨论】:

  • Gaierror 是 DNS 名称查找失败。您的主机是内部的吗?
  • 不是由其他公司管理。这家公司正在为我提供互联网连接。如何测试失败的主机?

标签: python ssl google-cloud-platform google-cloud-functions imap


【解决方案1】:

您是否为包含 Cloud Function 的项目添加了结算帐号?免费层上的函数无法与外部网络通信,并且将无法进行 DNS 查找。

【讨论】:

  • 对不起,不是说你便宜!在明确添加计费帐户之前,新创建的函数将处于免费层级。
  • 您需要为每个云功能添加计费吗??
  • 不,对于每个新项目。如果项目已经添加了账单,这可能不是原因。
猜你喜欢
  • 2021-11-05
  • 2013-07-01
  • 2016-11-16
  • 2013-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-05
  • 1970-01-01
相关资源
最近更新 更多