Reputation: 9
so im trying to make an async-requests thingy and i cant get the json data from a post
import grequests as requests
headers = {SOME HEADERS}
data = {
SOME DATA...
}
r = requests.post(
"some url (NOT A REAL URL)", headers=headers, data=data
)
var = r.json["SOME VALUE"]
NOTE: THE VALUES IN TH IS CODE AREN'T REAL
I tried to get the json value from r and it didnt work, i expected a json value from the r.json["SOME VALUE"] but instead i got an error: " 'builtin_function_or_method' object is not subscriptable "
Upvotes: 0
Views: 190
Reputation: 4608
r.json is a method. So you need to call it with parentheses first:
var = r.json() #type(var) -- > dictionary
var = var['SOME VALUE']
#or (shorter)
var = r.json()['SOME VALUE']
Upvotes: 2