So, you are using the amazing requests module of Python! So checked their sample code in the website: http://docs.python-requests.org/en/latest/ and the URL you are calling returns json content. So you followed their example and came up with a code like this:
import requests
url = '' # put your url here
r = requests.get(url)
json_content = r.json()
print json_content
When you run the program, you get the following error:
json_content = r.json()
TypeError: 'dict' object is not callable
Now you are wondering what is this! An example from the home page doesn't work. So you searched Google and came here. Now you solve the problem using
json_content = r.json instead of
json_content = r.json()
So this code will work (Python 2.7):
import requests
url = '' # put your url here
r = requests.get(url)
json_content = r.json
print json_content
If you are wondering why you got the error in the first code, let me give you a hint. Add the following lines to your Python code and see the output:
print type(r)
print type(r.json)
Comments
Post a Comment