Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadHeaderError when using logging errors via django.utils.log.AdminEmailHandler #22

Open
funvit opened this issue Feb 13, 2013 · 2 comments

Comments

@funvit
Copy link

funvit commented Feb 13, 2013

settings.py:

EMAIL_BACKEND = 'django_mailer.smtp_queue.EmailBackend'

in code somewere:

except Exception, e:
    logger.error('discount_cards.views.register -> new_user.save -> %s' % e.message)

raise BadHeaderError: Header values can't contain newlines

truncated traceback:

File "/u01/funvit/nginx/env/lib/python2.6/site-packages/django/utils/log.py", line 101, in emit
  html_message=html_message)

File "/u01/funvit/nginx/env/lib/python2.6/site-packages/django/core/mail/__init__.py", line 96, in mail_admins
  mail.send(fail_silently=fail_silently)

File "/u01/funvit/nginx/env/lib/python2.6/site-packages/django/core/mail/message.py", line 251, in send
  return self.get_connection(fail_silently).send_messages([self])

File "/u01/funvit/nginx/env/src/django-mailer/django_mailer/smtp_queue.py", line 31, in send_messages
  queue_email_message(email_message)

File "/u01/funvit/nginx/env/src/django-mailer/django_mailer/__init__.py", line 122, in queue_email_message
  encoded_message=email_message.message().as_string())

File "/u01/funvit/nginx/env/lib/python2.6/site-packages/django/core/mail/message.py", line 219, in message
  msg['Subject'] = self.subject

File "/u01/funvit/nginx/env/lib/python2.6/site-packages/django/core/mail/message.py", line 127, in __setitem__
  name, val = forbid_multi_line_headers(name, val, self.encoding)

File "/u01/funvit/nginx/env/lib/python2.6/site-packages/django/core/mail/message.py", line 87, in forbid_multi_line_headers
  raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))

BadHeaderError: Header values can't contain newlines (got u'[Django] ERROR: discount_cards.views.register -> new_user.save -> value too long for type character varying(30)\n' for header 'Subject')

im currently testing dirty patch via adding at start of def queue_email_message

# file: __init__.py

email_message.subject = email_message.subject.replace(u'\n', u' ')
@SmileyChris
Copy link
Owner

This sounds like an old Django issue. At least in 1.4, the AdminEmailHandler ensures the subject is devoid of new lines and isn't longer than 989 chars.

@funvit
Copy link
Author

funvit commented Feb 14, 2013

yes, Django 1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants