#1384 closed defect (fixed)
ugly bug in mail_admins()
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
mail_admins() doesn't catch SMTP Exceptions internally so if an error happens in mail_admins the exception gets shown to the user (in my case FLUP generates the exception view since i'm using FCGI) which is very ugly - and it just showed my email address to our customers.
trace below, plaese add try/catch where aproppriate.
/usr/lib/python2.4/site-packages/flup/server/fcgi_base.py in run(self=<flup.server.fcgi_base.Request object>)
558 """Runs the handler, flushes the streams, and ends the request."""
559 try:
560 protocolStatus, appStatus = self.server.handler(self)
561 except:
562 traceback.print_exc(file=self.stderr)
protocolStatus undefined, appStatus undefined, self = <flup.server.fcgi_base.Request object>, self.server = <flup.server.fcgi_fork.WSGIServer object>, self.server.handler = <bound method WSGIServer.handler of <flup.server.fcgi_fork.WSGIServer object>>
/usr/lib/python2.4/site-packages/flup/server/fcgi_base.py in handler(self=<flup.server.fcgi_fork.WSGIServer object>, req=<flup.server.fcgi_base.Request object>)
1096 self._appLock.acquire()
1097 try:
1098 result = self.application(environ, start_response)
1099 try:
1100 for data in result:
result = None, self = <flup.server.fcgi_fork.WSGIServer object>, self.application = <django.core.handlers.wsgi.WSGIHandler instance>, environ = {'DOCUMENT_ROOT': '/opt/lighttpd/wwwroot', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*', 'HTTP_ACCEPT_LANGUAGE': 'pl', 'HTTP_CACHE_CONTROL': 'max-age=259200', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'JSESSIONID=BAEE69B71D8B208C1E5F444481C875AA; jsi...VERID=s0; dsess2=62d459bbb6e44290db187bdb24100803', 'HTTP_HOST': 'w8.grono.net', 'HTTP_REFERER': 'http://w8.grono.net/logout/?javatoo=1', 'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)', ...}, start_response = <function start_response>
/opt/live1/django/core/handlers/wsgi.py in __call__(self=<django.core.handlers.wsgi.WSGIHandler instance>, environ={'DOCUMENT_ROOT': '/opt/lighttpd/wwwroot', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*', 'HTTP_ACCEPT_LANGUAGE': 'pl', 'HTTP_CACHE_CONTROL': 'max-age=259200', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_COOKIE': 'JSESSIONID=BAEE69B71D8B208C1E5F444481C875AA; jsi...VERID=s0; dsess2=62d459bbb6e44290db187bdb24100803', 'HTTP_HOST': 'w8.grono.net', 'HTTP_REFERER': 'http://w8.grono.net/logout/?javatoo=1', 'HTTP_USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)', ...}, start_response=<function start_response>)
157 try:
158 request = WSGIRequest(environ)
159 response = self.get_response(request.path, request)
160 finally:
161 db.db.close()
response undefined, self = <django.core.handlers.wsgi.WSGIHandler instance>, self.get_response = <bound method WSGIHandler.get_response of <django.core.handlers.wsgi.WSGIHandler instance>>, request = <DjangoRequest GET:<MultiValueDict: {'javatoo': ...gi.url_scheme': 'http', 'wsgi.version': (1, 0)}>, request.path = '/logout/'
/opt/live1/django/core/handlers/base.py in get_response(self=<django.core.handlers.wsgi.WSGIHandler instance>, path='/logout/', request=<DjangoRequest GET:<MultiValueDict: {'javatoo': ...gi.url_scheme': 'http', 'wsgi.version': (1, 0)}>)
115 request_repr = "Request repr() unavailable"
116 message = "%s\n\n%s" % (self._get_traceback(), request_repr)
117 mail_admins(subject, message, fail_silently=True)
118 return self.get_friendly_error_response(request, resolver)
119
mail_admins = <function mail_admins>, subject = 'Coding error (EXTERNAL IP): /logout/', message = 'Traceback (most recent call last):\n\n File "/opt...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', fail_silently undefined, builtin True = True
/opt/live1/django/core/mail.py in mail_admins(subject='Coding error (EXTERNAL IP): /logout/', message='Traceback (most recent call last):\n\n File "/opt...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', fail_silently=True)
52 "Sends a message to the admins, as defined by the ADMINS constant in settings.py."
53 from django.conf.settings import ADMINS, SERVER_EMAIL
54 send_mail(EMAIL_SUBJECT_PREFIX + subject, message, SERVER_EMAIL, [a[1] for a in ADMINS], fail_silently)
55
56 def mail_managers(subject, message, fail_silently=False):
global send_mail = <function send_mail>, global EMAIL_SUBJECT_PREFIX = '[Django] ', subject = 'Coding error (EXTERNAL IP): /logout/', message = 'Traceback (most recent call last):\n\n File "/opt...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', SERVER_EMAIL = 'root@localhost', a = 'wsobczuk@gmail.com', ADMINS = ('wsobczuk@gmail.com',), fail_silently = True
/opt/live1/django/core/mail.py in send_mail(subject='[Django] Coding error (EXTERNAL IP): /logout/', message='Traceback (most recent call last):\n\n File "/opt...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', from_email='root@localhost', recipient_list=['s'], fail_silently=True)
20 of the recipient list will see the other recipients in the 'To' field.
21 """
22 return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently)
23
24 def send_mass_mail(datatuple, fail_silently=False):
global send_mass_mail = <function send_mass_mail>, subject = '[Django] Coding error (EXTERNAL IP): /logout/', message = 'Traceback (most recent call last):\n\n File "/opt...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', from_email = 'root@localhost', recipient_list = ['s'], fail_silently = True
/opt/live1/django/core/mail.py in send_mass_mail(datatuple=[['[Django] Coding error (EXTERNAL IP): /logout/', 'Traceback (most recent call last):\n\n File "/opt...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', 'root@localhost', ['s']]], fail_silently=True)
44 msg['From'] = from_email
45 msg['To'] = ', '.join(recipient_list)
46 server.sendmail(from_email, recipient_list, msg.as_string())
47 num_sent += 1
48 server.quit()
server = <smtplib.SMTP instance>, server.sendmail = <bound method SMTP.sendmail of <smtplib.SMTP instance>>, from_email = 'root@localhost', recipient_list = ['s'], msg = <django.core.mail.SafeMIMEText instance>, msg.as_string = <bound method SafeMIMEText.as_string of <django.core.mail.SafeMIMEText instance>>
/usr/lib/python2.4/smtplib.py in sendmail(self=<smtplib.SMTP instance>, from_addr='root@localhost', to_addrs=['s'], msg='Content-Type: text/plain; charset="us-ascii"\nMIM...gi.url_scheme\': \'http\',\n \'wsgi.version\': (1, 0)}>', mail_options=[], rcpt_options=[])
686 # the server refused all our recipients
687 self.rset()
688 raise SMTPRecipientsRefused(senderrs)
689 (code,resp) = self.data(msg)
690 if code != 250:
global SMTPRecipientsRefused = <class smtplib.SMTPRecipientsRefused>, senderrs = {'s': (550, '<s>: Recipient address rejected: User unknown in local recipient table')}
SMTPRecipientsRefused: {'s': (550, '<s>: Recipient address rejected: User unknown in local recipient table')}
args = ({'s': (550, '<s>: Recipient address rejected: User unknown in local recipient table')},)
recipients = {'s': (550, '<s>: Recipient address rejected: User unknown in local recipient table')}
Change History (2)
comment:1 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:2 by , 20 years ago
Note:
See TracTickets
for help on using tickets.
(In [2433]) magic-removal: Fixed #1384 - ugly bug in mail_admins. Added additional try blocks.