Mar-25-2022, 09:41 PM
deanhystad Wrote:resp.json is a json string with all the interesting stuff. You can convert the json string to a Python dictionary to make it easier to work with.deanhystad as info so do Requests have build in
json
encoder/decoder added a long time ago(2014).So the extra step with json string trough json library is not recommend.
can also mess up encoding,
resp.json()
directly from Request dos a much better job of figuring out encoding used. >>> import requests >>> >>> resp = requests.get('https://github.com/timeline.json') >>> resp.json() {'documentation_url': 'https://docs.github.com/v3/activity/events/#list-public-events', 'message': 'Hello there, wayfaring stranger. If you’re reading this then you ' 'probably didn’t see our blog post a couple of years back ' 'announcing that this API would go away: http://git.io/17AROg Fear ' 'not, you should be able to get what you need from the shiny new ' 'Events API instead.'} >>> resp.json()['documentation_url'] 'https://docs.github.com/v3/activity/events/#list-public-events' >>> resp.encoding 'utf-8'