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

Django backend crashes when sending a message with attachments #98

Closed
suriya opened this issue Mar 11, 2017 · 4 comments
Closed

Django backend crashes when sending a message with attachments #98

suriya opened this issue Mar 11, 2017 · 4 comments

Comments

@suriya
Copy link
Contributor

suriya commented Mar 11, 2017

Postmarker's Django backend crashes when sending a message with attachments. The crash happens when therequests library tries to convert a dictionary containing email message information into a JSON string. The conversion fails for attachments.

Here's a stack trace.

  File "/home/vagrant/bookshelf.git/my-env/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 "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/django.py", line 57, in send_messages
    response = self.client.emails.send_batch(*prepared_messages, TrackOpens=self.get_option('TRACK_OPENS'))
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/models/emails.py", line 324, in send_batch
    return self.EmailBatch(*emails).send(**extra)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/models/emails.py", line 245, in send
    responses = [self._manager._send_batch(*batch) for batch in chunks(emails, self.MAX_SIZE)]
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/models/emails.py", line 268, in _send_batch
    return self.call('POST', '/email/batch', data=emails)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/models/base.py", line 63, in call
    return self.client.call(*args, **kwargs)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/core.py", line 84, in call
    **kwargs
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/postmarker/core.py", line 106, in _call
    response = self.session.request(method, url, json=data, params=kwargs, headers=default_headers)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/requests/sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/requests/sessions.py", line 407, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/requests/models.py", line 305, in prepare
    self.prepare_body(data, files, json)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/requests/models.py", line 462, in prepare_body
    body = complexjson.dumps(json)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/simplejson/__init__.py", line 280, in dumps
    def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
    return _iterencode(o, 0)
  File "/home/vagrant/bookshelf.git/my-env/local/lib/python2.7/site-packages/simplejson/encoder.py", line 268, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <django.core.mail.message.SafeMIMEText instance at 0x7f15eacc8e18> is not JSON serializable
@Stranger6667
Copy link
Owner

Hello @suriya !
Thank you for the bug report! I found out how to fix the problem, and I'll submit bugfix release in next few hours.

@Stranger6667
Copy link
Owner

0.7.2 bugfix release is on PyPI now :)

@suriya
Copy link
Contributor Author

suriya commented Mar 12, 2017

Thank you so much! I am amazed and really appreciate your rapid and thorough response!

@suriya
Copy link
Contributor Author

suriya commented May 27, 2018

@Stranger6667 Is this working for you? I am getting the same exception with Python 2.7, Django 1.11 as well as Python 3.6, Django 1.11.

I get

TypeError: Object of type 'SafeMIMEText' is not JSON serializable

and I am unable to debug the issue.

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