Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to smtp server with Django when using gevent socket.py

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

like image 657
Kevin Avatar asked Aug 15 '11 22:08

Kevin


1 Answers

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'.

like image 69
Kevin Avatar answered Sep 28 '22 02:09

Kevin