Skip to content Skip to sidebar Skip to footer

Response' Object Is Not Subscriptable Python Http Post Request

I am trying to post a HTTP request. I have managed to get the code to work but I am struggling returning some of the result. The result looks like this { 'requestId' : '8317cgs

Solution 1:

The response object contains much more information than just the payload. To get the JSON data returned by the POST request, you'll have to access response.json() as described in the example:

requestpost = requests.post(url, json=data, auth=(username, password))
response_data = requestpost.json()
print(response_data["requestId"])

Solution 2:

You should convert your response to a dict:

requestpost = requests.post(url, json=data, auth=(username, password))
res = requestpost.json()
print(res["requestId"])

Post a Comment for "Response' Object Is Not Subscriptable Python Http Post Request"