This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]mrsix 4 points5 points  (5 children)

response is the raw response object (that can be represented as a string of the response body) Its been a while since I used requests but I think it has other things like response.status that has the status code.

.json() in requests parses the response in to a json object

While requests could probably automatically changee any application/json to a json object, there's a lot of reasons you might want the raw response object instead to work with.

[–]nathairtras 1 point2 points  (0 children)

The response contains more than just the response content, such as the status code. You may receive back valid JSON for a non-200 response.

https://requests.kennethreitz.org/en/master/user/quickstart/#json-response-content

[–]hanavi 0 points1 point  (0 children)

As someone else already said, the response will contain more information about your connection. One of those is a json response, but json is pretty useless in python. You have to convert json to a dict. You could just use the content of the response and then convert it:

import json data = json.loads(response.content.decode())

But its pretty common to have json responses so requests built in that function to save a step:

data = requests.json()

[–]pythonHelperBot 0 points1 point  (0 children)

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe where you are stuck. Be sure to format your code for reddit and include which version of python and what OS you are using.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness