Skip to content

No JSON object could be decoded #11

Closed

Description

@kdmny

I'm having a transient issue with the library. Every so often, the get call below fails. Waiting a few seconds and retrying to call usually fixes it so I suspect the remote server is responding with something unexpected. Clients can easily catch and retry, but it would be nice if the library gracefully failed and gave consumers a clearer picture of the cause so they can adapt appropriately.

start=(datetime.datetime.now() - datetime.timedelta(hours=1)).isoformat()
params = urllib.urlencode({'start': start})
res = api.get("/v3/reporting/logs.json?{0}".format(params))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/maxcdn/maxcdn.py", line 40, in get
    **kwargs).json()
  File "/Library/Python/2.7/site-packages/requests/models.py", line 797, in json
    return json.loads(self.text, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Activity

  1. jmervine commented on Dec 17, 2014

    @jmervine

    @kdmny I agree. I'm wondering if perhaps it's an empty response or something like that. I'll take a look when I have a sec and get back to you. Cheers!

  2. self-assigned this
    on Dec 17, 2014
  3. jmervine commented on Dec 17, 2014

    @jmervine

    Empty response should look like this:

    {
      "limit": 100,
      "page": 1,
      "request_time": 16,
      "next_page_key": null,
      "records": []
    }
    

    So that's not it. The next step will probably be to update the module to include better error checking from the server, so the error can be passed on to support@maxcdn.com for server side debugging.

  4. jmervine commented on Dec 17, 2014

    @jmervine

    @kdmny (cc @jdorfman) What would your preferred handling be here?

    1. Throw an exception with the status code and raw body of the response.
    2. Return a dictionary with { 'error': raw_body, 'status_code': status_code }
    3. Raw response returned in place of parsed json.
    4. curl style response return in place of parsed json, e.g.:
    404 Not Found https://rws.maxcdn.com/jmervine/v3/badreporting/logs.json?start=2014-12-17T14%3A34%3A11.601499
    content-encoding: gzip
    transfer-encoding: chunked
    set-cookie: PHPSESSID=b8r1i7hgqdadv8vg3s6i6a5jd7; path=/; secure; HttpOnly
    expires: Thu, 19 Nov 1981 08:52:00 GMT
    vary: Accept-Encoding
    server: nginx
    connection: keep-alive
    pragma: no-cache
    cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    date: Wed, 17 Dec 2014 22:35:12 GMT
    access-control-allow-origin: *
    content-type: application/json
    
    raw content here
    
  5. jmervine commented on Dec 17, 2014

    @jmervine

    I'm thinking a custom ValueError, something like:

    Traceback (most recent call last):
      File "<stdin>", line 4, in <module>
    ValueError: No JSON object could be decoded. Raw response was:
    
    raw response here

    See pull request #12

  6. added a commit that references this issue on Dec 19, 2014
  7. jmervine commented on Dec 19, 2014

    @jmervine

    @kdmny (cc/ @jimaek)

    So I've released these changes. See: https://github.com/MaxCDN/python-maxcdn/releases/tag/v0.0.6 for details. I'm going to close this issue, although I understand the underlying issues hasn't really been fixed. With the additional error logging you should be able to grab information about the real issue. You can then either open a new request here, if it's related to this package, or send an email to support@maxcdn.com, if it's API / server related.

    Let me know if you have any other questions, comments, etc.

    Cheers,
    J

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions