Skip to content

json.decoder.JSONDecodeError when processing empty server responses #7

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

Closed
wants to merge 1 commit into from

Conversation

zmbbb
Copy link

@zmbbb zmbbb commented Apr 24, 2018

Hey, really like your lib and the elegant interface.

I encountered an exception (see below) when I received an empty response from the server, in this case a "204 NO CONTENT". The lib forwarded the empty response to JSON for decoding which raised the exception. As a quick fix, I added a check whether client_response.text is True. This works for me, for empty and non-empty responses.

The exception:
[...]
File "/usr/local/lib/python3.5/dist-packages/simple_rest_client/resource.py", line 107, in action_method
return make_request(self.session, request)
File "/usr/local/lib/python3.5/dist-packages/simple_rest_client/decorators.py", line 39, in wrapper
response = f(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/simple_rest_client/request.py", line 30, in make_request
body = json.loads(client_response.text)
File "/usr/local/lib/python3.5/dist-packages/json_encoder/json/init.py", line 229, in loads
**kw
File "/usr/lib/python3.5/json/init.py", line 332, in loads
return cls(**kw).decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

…g empty server responses like 204 NO CONTENT
@codecov-io
Copy link

Codecov Report

Merging #7 into master will decrease coverage by 0.53%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
- Coverage     100%   99.46%   -0.54%     
==========================================
  Files           6        6              
  Lines         184      186       +2     
==========================================
+ Hits          184      185       +1     
- Misses          0        1       +1
Impacted Files Coverage Δ
simple_rest_client/request.py 97.29% <66.66%> (-2.71%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b7a0b8...27def86. Read the comment docs.

@allisson
Copy link
Owner

Hi @zmbbb,
Thanks for your report, i'll release version 0.5.2 with this fix ASAP.

#8

@allisson allisson closed this Apr 24, 2018
@zmbbb
Copy link
Author

zmbbb commented Apr 24, 2018

That was quick! :-D

Thank you very much!

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

Successfully merging this pull request may close these issues.

3 participants