我正在使用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
编辑:添加完整的追溯
答案 0 :(得分:7)
端口是一个字符串。当它被传递给_socket.getservbyname()时会导致一个难以理解的错误,它需要一个像'smtp'这样的字符串。
答案 1 :(得分:5)
我在settings.py中尝试使用EMAIL_PORT中的环境变量时遇到了同样的问题。环境变量默认返回一个字符串,但该端口必须是整数。我改变了我的设置:
EMAIL_PORT = os.environ.get('MAILGUN_SMTP_PORT', 25)
为:
EMAIL_PORT = int(os.environ.get('MAILGUN_SMTP_PORT', 25))
答案 2 :(得分:0)
你能试试gevent-1.0a2吗?它有一个完全不同的DNS实现。