简体   繁体   中英

POST > Connection timed out Django

I just installed Django on Ubuntu 12.04 and try to send a message I get the following error:

#from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['email@gmail.com'])
send.email()

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 255, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 88, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 49, in open
    local_hostname=DNS_NAME.get_fqdn())
  File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 309, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
    return socket.create_connection((port, host), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 110] Connection timed out

The funny thing is that I have the same problem with Haystack

[error] 19704#0: *10 upstream prematurely closed connection while reading response header from upstream, client: 201.2*3.**.85, server: www.myserver.com, request: "POST /account/register/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "www.myserver.com", referrer: "http://www.myserver.com/account/register/"


#uWSGI Configuration

[uwsgi]
uid = www-data
gid = www-data
chdir = /var/www/myserver.com/virtual/project
virtualenv = /var/www/myserver.com/virtual
plugins = python
master = True
vacuum = True
processes = 2
harakiri = 12
post-buffering = 4096
max-requests = 4000
module = project.wsgi:application

Thanks.

To send email in django , you must define the following settings in your settings.py . Also make sure that the email host and login details are correct.

EMAIL_HOST          = 'smtp.gmail.com'
EMAIL_PORT          = 587
EMAIL_HOST_USER     = 'name@gmail.com'
EMAIL_HOST_PASSWORD = 'gmail_password'
EMAIL_USE_TLS       = True
EMAIL_BACKEND       = 'django.core.mail.backends.smtp.EmailBackend'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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