brack3t / Djrill

[INACTIVE/UNMAINTAINED] Djrill is an email backend and new message class for Django users that want to take advantage of the Mandrill transactional email service from MailChimp.
BSD 3-Clause "New" or "Revised" License
319 stars 64 forks source link

ValueError: No JSON object could be decoded #93

Closed aisayko closed 9 years ago

aisayko commented 9 years ago

Hello,

I just installed Djrill and try to send test message:

from django.core.mail import send_mail
send_mail("It works!", 
          "This will get sent through Mandrill", 
          "mail@mysite.com>", 
          ["someuser@example.com"], 
          html_message="<strong>This will</strong> get sent through Mandrill")

The message is sent successfully to user but the code raise the next error:

/home/user/venvpath/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/user/venvpath/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/user/venvpath/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/user/venvpath/local/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 81, in send_messages
    sent = self._send(message)
  File "/home/user/venvpath/local/lib/python2.7/site-packages/djrill/mail/backends/djrill.py", line 153, in _send
    message.mandrill_response = response.json()
  File "/home/user/venvpath/local/lib/python2.7/site-packages/requests/models.py", line 819, in json
    return json.loads(self.text, **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Python == 2.7.6 Django == 1.8.2 djrill == 1.4.0

Many thanks for any help.

medmunds commented 9 years ago

This can occur if the response from Mandrill is being truncated or altered. I'd guess the problem may be related to the urllib3 warning you're seeing:

InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

The link they provide has some suggestions.

aisayko commented 9 years ago

Next steps solved the issue:

apt-get install libffi-dev libssl-dev
pip install requests[security] --upgrade

Thanks!

medmunds commented 9 years ago

Glad you found a solution.

For anyone else reading this issue because you're seeing an InsecurePlatformWarning when using Djrill, the solution is either:

More details here.

McaDipali commented 7 years ago

data = urllib.urlencode(parameters).encode('utf-8') content = urllib2.urlopen(url=token_url, data=data) try: string = content.read() json_obj = json.loads(string.decode('utf-8')) print json_obj except ValueError as a: print a else: print json_obj

any one have idea it gives value error like " No JSON object could be decoded"

McaDipali commented 7 years ago

@aisayko i tried this but it give me still error.....

medmunds commented 7 years ago

@McaDipali are you having a problem with the Djrill package? The code you posted doesn't look like anything from Djrill.

If your question is not about Djrill, please ask it on StackOverflow.

If you are having problems with Djrill, it might be better to open a new issue. Be sure to say what versions of Djrill, Django, requests, and Python you are using; what specifically you are trying to do that's not working; and include any stack trace from the failure. (Also, please note that Djrill is no longer being supported.)