I have written the following code to read sample JSON data from url,
HEADER = {"content-type": "application/josn"}
session = requests.Session()
session.verify = True
session.headers = HEADER
output = session.request("GET", "https://jsonplaceholder.typicode.com/todos/1", timeout=30)
If I print output I get,
<Response [200]>
If I do,
output = session.request("GET", "https://jsonplaceholder.typicode.com/todos/1", timeout=30).json()
I get actual json content,
{u'completed': False, u'userId': 1, u'id': 1, u'title': u'delectus aut autem'}
But when I do,
output = session.request("GET", "https://jsonplaceholder.typicode.com/todos/1", timeout=30)
print(json.loads(output))
I get,
File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
Can someone please give an example to me when should I use .json() and when json.loads()?
HEADERdeclaration has a typo:application/josnshould beapplication/json.