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

Special case? ValueError: "No JSON object could be decoded" for JSON response with an empty body #38

Closed
kiminoa opened this issue Jun 10, 2015 · 2 comments

Comments

@kiminoa
Copy link

kiminoa commented Jun 10, 2015

======================================================================
ERROR: test_request (gabbi.driver.test_env_loader_env_notes_delete_environment_note)
gabbi.driver.test_env_loader_env_notes_delete_environment_note.test_request
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/gabbi/case.py", line 78, in wrapper
    func(self)
  File "/Library/Python/2.7/site-packages/gabbi/case.py", line 118, in test_request
    self._run_test()
  File "/Library/Python/2.7/site-packages/gabbi/case.py", line 312, in _run_test
    self._run_request(full_url, method, headers, body)
  File "/Library/Python/2.7/site-packages/gabbi/case.py", line 279, in _run_request
    self.json_data = json.loads(decoded_output)
  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
defaults:
    request_headers:
        accept: application/json
        content-type: application/json
    response_headers:
        content-type: application/json

tests:
    - name: delete environment note
      verbose: True
      method: DELETE
      # Use previous $RESPONSE to get note ID
      url: /v2/notes/$RESPONSE['$.id']
      status: 302 || 200

Response body: empty
Response headers:

Status Code: 200
X-Runtime: 0.302572
Date: Wed, 10 Jun 2015 17:37:25 GMT
Content-Encoding: gzip
X-Rack-Cache: invalidate, pass
Server: nginx
ETag: W/"7215ee9c7d9dc229d2921a40e899ec5f"
Vary: Accept-Encoding
Content-Type: application/json; charset=utf-8
Status: 200 OK
Cache-Control: max-age=0, private, must-revalidate
Transfer-Encoding: chunked
Connection: keep-alive
X-Request-Id: 1d3efa9239c321a00155be9e1d44324f
X-UA-Compatible: IE=Edge,chrome=1
@kiminoa kiminoa changed the title Special case? ValueError: No JSON object could be decoded for JSON response with an empty body Special case? ValueError: "No JSON object could be decoded" for JSON response with an empty body Jun 10, 2015
@kiminoa
Copy link
Author

kiminoa commented Jun 10, 2015

PEBKAC.

My workaround was to nix the default headers' content-type and individually specify them for each test. This specific test wanted a javascript response, but test-specific headers didn't override the default. I'll file a separate issue for that for consideration.

I don't know if there's a use case where an empty JSON body could happen where this is still a bug, but in our case, the DELETE issues a javascript response my default.

@kiminoa kiminoa closed this as completed Jun 10, 2015
@cdent
Copy link
Owner

cdent commented Jun 11, 2015

Note that this error can only happen if there was something other than an empty string in the body of your response because of this line which basically says "only decode the body if there is a body and the content type says 'json'".

So it seems there's something weird going on with the body of your response?

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