How to get JSON data from a post in grequests library (async-requests) python

115 Views Asked by At

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 "

1

There are 1 best solutions below

0
On

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']