I'm running Django with an Apache2 server on an Ubuntu backend. On load of my site, I get a 500 internal server error. The Apache log looks like:
AH00094: Command line: '/usr/sbin/apache2'
mod_wsgi (pid=9568): Exception occurred processing WSGI script '/home/ubuntu/project/project/wsgi.py'.
Traceback (most recent call last):
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site- packages/django/core/handlers/wsgi.py", line 177, in __call__
response = self.get_response(request)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 216, in get_response
'request': request
File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
self._log(ERROR, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1271, in _log
self.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1281, in handle
self.callHandlers(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1321, in callHandlers
hdlr.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 749, in handle
self.emit(record)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/utils/log.py", line 117, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/utils/log.py", line 120, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 97, in mail_admins
mail.send(fail_silently=fail_silently)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/core/mail/message.py", line 292, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 111] Connection refused
This looks to me to be an error when the mail_admins method is called. I can post the contents of wsgi.py or other files if that is needed. My application involves no explicit email usage, so I'm not sure how this is happening. Any ideas? Thanks.
Django has a special logger for sending an email to admins when a 500-error occurs. Check out https://docs.djangoproject.com/en/1.9/topics/logging/#django.utils.log.AdminEmailHandler for more info.
It seems that an exception is thrown and django tries to propagate it by sending you an email, but the email cannot be send so you get another exception! Probably the cause of the real exception is before the exception that is caused by unable to send the email. However, I propose to fix your email configuration so that django will be able to send you these emails when a 500-error occurs, it is a nice feature (and a first step to a full exception tracker like Sentry). If, for some reason you are unable to send emails from that server then I recommend at least to configure your email backend (https://docs.djangoproject.com/en/1.9/topics/email/#email-backends) to either console (EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend') or file
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/tmp/app-messages' # change this to a proper location
so that the mail backend will work.
Related
I am try to send email in my django project using Celery and RabbitMQ.
Here is my project on GitHub https://github.com/Loctarogar/Django-by-Example.
In my tasks.py file typed admin#myshop.com but i tried change it to my real google mail and that have no effects.
Every time I have this Error:
[2017-11-20 20:09:36,747: ERROR/ForkPoolWorker-4] Task orders.tasks.order_created[a8fe13ed-08dc-4971-82ff-f184e197ab8d] raised unexpected: ConnectionRefusedError(111, 'Connection refused')
Traceback (most recent call last):
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/app/trace.py", line 374, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/morilon/dj/shop/lib/python3.5/site-packages/celery/app/trace.py", line 629, in __protected_call__
return self.run(*args, **kwargs)
File "/home/morilon/dj/shop/myshop/orders/tasks.py", line 14, in order_created
mail_sent = send_mail(subject, message, 'admin#myshop.com', [order.email])
File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/__init__.py", line 62, in send_mail
return mail.send()
File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/message.py", line 348, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 104, in send_messages
new_conn_created = self.open()
File "/home/morilon/dj/shop/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 64, in open
self.connection = self.connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python3.5/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.5/smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.5/smtplib.py", line 306, in _get_socket
self.source_address)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
I had exactly the same problem, but I solved it by setting up my settings.py just like skulegirl says, and just add this to my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
I hope it helps you.
Your code repo is configured to use the console backend for emails, but your backtrace is showing the smtp backend is being used. I assume you've changed the backend and that's what's causing the error.
By default, the smtp backend looks for an smtp server on localhost. I'm guessing you don't have one running there.
If you want to send via gmail's smtp servers you can do so, you just need to configure the approriate settings in your settings.py file. See the django docs for what needs to be configured. Read the gmail docs for the exact smtp host address to use.
I'm trying to set up self-serve password resets on a django setup. I have configured it to use the in-built password reset system, and have tested everything on my dev machine, and works fine. However, in production (i.e. actually sending emails), when I try to get a password reset email, it throws an SMTPServerDisconnected error:
[22/Sep/2017 15:04:59] ERROR [django.request:256] Internal Server Error: /password_reset/
Traceback (most recent call last):
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner
return func(*args, **kwargs)
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/contrib/auth/views.py", line 182, in password_reset
form.save(**opts)
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 256, in save
html_email_template_name=html_email_template_name)
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 213, in send_mail
email_message.send()
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 107, in send_messages
sent = self._send(message)
File "/srv/virtualenvs/sis_esv/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 123, in _send
self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
File "/usr/lib/python2.7/smtplib.py", line 735, in sendmail
self.rset()
File "/usr/lib/python2.7/smtplib.py", line 469, in rset
return self.docmd("rset")
File "/usr/lib/python2.7/smtplib.py", line 394, in docmd
return self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 368, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
SMTPServerDisconnected: Connection unexpectedly closed
I'm using G-Suite (Google) as the SMTP relay; the settings I'm using are:
EMAIL_HOST = 'smtp-relay.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
The weird thing is I can send emails fine in other places within the system, using django's django.core.mail.send_mail() function.
The problem turned out to be that I hadn't set DEFAULT_FROM_EMAIL, thus django was attempting to send from a localhost email address, which Google's SMTP servers silently rejected. In other uses for send_mail() I had specified the from address, so this didn't appear as an issue there.
I'm trying to write code to view messages from my g-mail, then search in the latest message for a certain phrase, that triggers a command.
But I'm having problems with connecting to my g-mail
from imapclient import IMAPClient
HOST = 'imap.gmail.com'
USERNAME = 'email'
PASSWORD = 'password'
ssl = False
server = IMAPClient(HOST, use_uid=True, ssl=ssl)
server.login(USERNAME, PASSWORD)
server.select_folder('INBOX')
print ('success')
I just added the 'success' at the end to make sure it worked, I'm using imap here but I tried pop which seems to be more confusing.
When I run this code i get this.
Traceback (most recent call last):
File "C:/Users/Yousef/Desktop/parser.py", line 8, in <module>
server = IMAPClient(HOST, use_uid=True, ssl=ssl)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\imapclient.py", line 152, in __init__
self._imap = self._create_IMAP4()
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\imapclient.py", line 166, in _create_IMAP4
return imap4.IMAP4WithTimeout(self.host, self.port, self._timeout)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\imap4.py", line 13, in __init__
imaplib.IMAP4.__init__(self, address, port)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-
32\lib\imaplib.py", line 197, in __init__
self.open(host, port)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-
32\lib\imaplib.py", line 294, in open
self.sock = self._create_socket()
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\imap4.py", line 16, in _create_socket
return socket.create_connection((self.host, self.port), self._timeout)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-
32\lib\socket.py", line 722, in create_connection
raise err
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-
32\lib\socket.py", line 713, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
Someone please help me with this, because this is my first time using imap/pop.
when I put ssl to true, I get this...
Traceback (most recent call last):
File "C:\Users\Yousef\Desktop\parser.py", line 8, in <module>
server = IMAPClient(HOST, use_uid=True, ssl=ssl)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\imapclient.py", line 152, in __init__
self._imap = self._create_IMAP4()
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\imapclient.py", line 164, in _create_IMAP4
self._timeout)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\tls.py", line 171, in __init__
imaplib.IMAP4.__init__(self, host, port)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-
32\lib\imaplib.py", line 197, in __init__
self.open(host, port)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\tls.py", line 177, in open
self.sock = wrap_socket(sock, self.ssl_context, host)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\tls.py", line 144, in wrap_socket
ssl_context = create_default_context()
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\imapclient\tls.py", line 127, in create_default_context
context.load_verify_locations(cadata=certs)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\backports\ssl\core.py", line 654, in load_verify_locations
self._ctx.load_verify_locations(cafile, capath)
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\OpenSSL\SSL.py", line 669, in load_verify_locations
_raise_current_error()
File "C:\Users\Yousef\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: []
nvm i found a solution, thanks for the help anyways.
I'm trying to configure a website using Django 1.8 and Plesk, and setting the email variables to any value gets the traceback below. I've tried with Gmail and the email server from the host, and the error is the same. I have tested Python's smtplib and successfully sent an email through that, so it looks like it may be something between Django and Plesk. If I set up the website on a test CentOS 6 server, then I don't run into this problem.
Example Config settings
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_PASSWORD = "mypassword"
EMAIL_HOST_USER = "user#gmail.com"
EMAIL_PORT = 587
Traceback
mod_wsgi (pid=1703): Exception occurred processing WSGI script '/var/www/vhosts/s1085163.instanturl.net/oozoa.wsgi'.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/whitenoise/base.py", line 119, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 218, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 256, in handle_uncaught_exception
'request': request
File "/usr/local/lib/python2.7/logging/__init__.py", line 1185, in error
self._log(ERROR, msg, args, **kwargs)
File "/usr/local/lib/python2.7/logging/__init__.py", line 1278, in _log
self.handle(record)
File "/usr/local/lib/python2.7/logging/__init__.py", line 1288, in handle
self.callHandlers(record)
File "/usr/local/lib/python2.7/logging/__init__.py", line 1328, in callHandlers
hdlr.handle(record)
File "/usr/local/lib/python2.7/logging/__init__.py", line 751, in handle
self.emit(record)
File "/usr/local/lib/python2.7/site-packages/django/utils/log.py", line 129, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/usr/local/lib/python2.7/site-packages/django/utils/log.py", line 132, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins
mail.send(fail_silently=fail_silently)
File "/usr/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/usr/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/local/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/local/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/local/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno -2] Name or service not known
Might be there is an issues with the firewall. Please try to disabled plesk firewall and IPtables on your server for the testing purpose and check it again.
This is a code for posting on a blog. It is my first try. I dont know what is the error in it. I am using proxy server and the error I'm getting is connection to server failed.
Can anyone help me out pleaseeeeeeeeee :/
import wordpresslib
# dummy data to be on safe side
data = "Post content, just ensuring data is not empty"
url='http://agneesa.wordpress.com/wordpress/xmlrpc.php'
# insert correct username and password
wp=wordpresslib.WordPressClient(url,'agnsa','pan#13579')
wp.selectBlog(0)
post=wordpresslib.WordPressPost()
post.title='try'
post.description=data
idPost=wp.newPost(post,True)
here is the traceback
here is the traceback file
Traceback (most recent call last):
File "C:\Python27\Lib\example.py", line 34, in <module>
post.categories = (wp.getCategoryIdFromName('Python'),)
File "C:\Python27\Lib\wordpresslib.py", line 332, in getCategoryIdFromName
for c in self.getCategoryList():
File "C:\Python27\Lib\wordpresslib.py", line 321, in getCategoryList
self.user, self.password)
File "C:\Python27\Lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "C:\Python27\Lib\xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "C:\Python27\Lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Python27\Lib\xmlrpclib.py", line 1292, in single_request
self.send_content(h, request_body)
File "C:\Python27\Lib\xmlrpclib.py", line 1439, in send_content
connection.endheaders(request_body)
File "C:\Python27\Lib\httplib.py", line 954, in endheaders
self._send_output(message_body)
File "C:\Python27\Lib\httplib.py", line 814, in _send_output
self.send(msg)
File "C:\Python27\Lib\httplib.py", line 776, in send
self.connect()
File "C:\Python27\Lib\httplib.py", line 757, in connect
self.timeout, self.source_address)
File "socket.py", line 571, in create_connection
raise err
error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
From the looks of your site, the url you posted returns a 404 (not actually there). However, this does seem ready to receive POST requests: http://agneesa.wordpress.com/xmlrpc.php
I suggest you try checking that URL for accuracy.
This is what I get when I try your code with your original URL:
xmlrpclib.ProtocolError: <ProtocolError for \
agneesa.wordpress.com/wordpress/xmlrpc.php: 404 Not Found>
This is what I get when I try it with the modified URL:
wordpresslib.WordPressException: \
<WordPressException 403: 'Bad login/pass combination.'>
... obviously because thats not your real account info. In a nutshell, its possible your proxy could also be contributing to problems if its not set up to properly forward the request, but without us knowing specifics about your proxy config, there is no way to know for sure.