requests icon indicating copy to clipboard operation
requests copied to clipboard

Incorrect json() docstring

Open alekna opened this issue 5 years ago • 3 comments

What json() actually does - it deserializes JSON into a Python object.

So the docstring below must be wrong: https://github.com/psf/requests/blob/fab1fd10d0b115e635b9ef1364f8444089725000/requests/models.py#L894-L918

alekna avatar Oct 23 '19 12:10 alekna

Do you mind if I take this task as an intro issue to the project? I'm looking to be a new contributor

albendz avatar Oct 31 '19 16:10 albendz

This has tripped me up as well. I'm new to Python. I expected response.json() to return JSON, but it doesn't. I don't know if I'm expected to do something further to turn it into actual JSON (and if so, what), or if this is an oversight in the requests code.

lousyd avatar May 25 '21 14:05 lousyd

I also ran into issues with this - besides the fact that it indeed returns a decoded Python representation of the content, I'm confused by the "if any" clause - there is nothing that checks the existence of content, nor if the response actually has Content-Type application/json set, it simply dumps self.text into a json loader.

So a better way to phrase this might be along the lines of: "Tries to return a decoded representation of the response's content as if it were JSON"

toothstone avatar Nov 15 '21 11:11 toothstone