使用gevent socket.py时无法使用Django连接到smtp服务器

发布于 2024-11-29 11:18:06 字数 2904 浏览 2 评论 0原文

我正在使用 gevent 在 Gunicorn 0.12.2 上运行 django 应用程序,并安装在 virtualenv 环境中。当我尝试连接到 smtp.gmail.com (django-registration 创建帐户视图)时,出现以下错误:

Traceback:
File "/home/.../env/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args,       **callback_kwargs)
File "/home/.../web/www/registration/views.py" in register
  148.             new_user = form.save(profile_callback=profile_callback)
File "/home/.../web/www/registration/forms.py" in save
  87.                                                              profile_callback=profile_callback)
File "/home/.../web/www/registration/models.py" in create_inactive_user
  127.             send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,  [new_user.email])
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/__init__.py" in send_mail
  61.                         connection=connection).send()
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/message.py" in send
  251.         return self.get_connection(fail_silently).send_messages([self])
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in send_messages
  79.             new_conn_created = self.open()
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in open
  42.                                            local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib/python2.6/smtplib.py" in __init__
  239.             (code, msg) = self.connect(host, port)
File "/usr/lib/python2.6/smtplib.py" in connect
  295.         self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.6/smtplib.py" in _get_socket
  273.         return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.6/socket.py" in create_connection
  500.     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/socket.py" in getaddrinfo
  653.     return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/resolver_ares.py" in getaddrinfo
  149.                 return self._getaddrinfo(host, port, family, socktype, proto, flags)
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/resolver_ares.py" in _getaddrinfo
  98.         port, socktype = self._lookup_port(port, socktype)
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/resolver_ares.py" in _lookup_port
  80.                     raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')

Exception Type: gaierror at /accounts/register/
Exception Value: [Errno -8] Servname not supported for ai_socktype

编辑:添加了完整的回溯

I'm running a django app on gunicorn 0.12.2 using gevent and installed in a virtualenv environment. When I try to connect to smtp.gmail.com (the django-registration create account view) I get the following error:

Traceback:
File "/home/.../env/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args,       **callback_kwargs)
File "/home/.../web/www/registration/views.py" in register
  148.             new_user = form.save(profile_callback=profile_callback)
File "/home/.../web/www/registration/forms.py" in save
  87.                                                              profile_callback=profile_callback)
File "/home/.../web/www/registration/models.py" in create_inactive_user
  127.             send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,  [new_user.email])
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/__init__.py" in send_mail
  61.                         connection=connection).send()
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/message.py" in send
  251.         return self.get_connection(fail_silently).send_messages([self])
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in send_messages
  79.             new_conn_created = self.open()
File "/home/.../env/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in open
  42.                                            local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib/python2.6/smtplib.py" in __init__
  239.             (code, msg) = self.connect(host, port)
File "/usr/lib/python2.6/smtplib.py" in connect
  295.         self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.6/smtplib.py" in _get_socket
  273.         return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.6/socket.py" in create_connection
  500.     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/socket.py" in getaddrinfo
  653.     return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/resolver_ares.py" in getaddrinfo
  149.                 return self._getaddrinfo(host, port, family, socktype, proto, flags)
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/resolver_ares.py" in _getaddrinfo
  98.         port, socktype = self._lookup_port(port, socktype)
File "/home/.../env/lib/python2.6/site-packages/gevent-1.0a2-py2.6-linux-x86_64.egg/gevent/resolver_ares.py" in _lookup_port
  80.                     raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')

Exception Type: gaierror at /accounts/register/
Exception Value: [Errno -8] Servname not supported for ai_socktype

EDIT: added full traceback

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲念泪 2024-12-06 11:18:06

端口是一个字符串。当它被传递给 _socket.getservbyname() 时,这会导致无法破译的错误,该错误需要一个诸如“smtp”之类的字符串。

the port was a string. this was causing an undecipherable error when it was passed to _socket.getservbyname(), which expects a string such as 'smtp'.

妳是的陽光 2024-12-06 11:18:06

当我尝试在 EMAIL_PORT 的 settings.py 中使用环境变量时,我遇到了同样的问题。环境变量默认返回字符串,但端口必须是整数。我将设置从: 更改

EMAIL_PORT = os.environ.get('MAILGUN_SMTP_PORT', 25)

为:

EMAIL_PORT = int(os.environ.get('MAILGUN_SMTP_PORT', 25))

I had this same problem when trying to use an environment variable in my settings.py for EMAIL_PORT. The environment variable returns a string by default, but the port must be an integer. I changed my settings from:

EMAIL_PORT = os.environ.get('MAILGUN_SMTP_PORT', 25)

to:

EMAIL_PORT = int(os.environ.get('MAILGUN_SMTP_PORT', 25))
失而复得 2024-12-06 11:18:06

您可以尝试 gevent-1.0a2 吗?它有一个完全不同的 DNS 实现。

Could you try gevent-1.0a2? It has a completely different DNS implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文