Reputation: 463
I am very new to python and attempting to parse through what appears to be JSON data.
import requests
import json
URL = "http://myip/cgi-bin/lun/luci/;stok=/login?form=login"
payload = {
'operation': 'login',
'username': 'someuser',
'password': 'somepassword'
}
session = requests.session()
r = requests.post(URL, data=payload)
print (r.json())
What I get back is:
{u'data': {u'stok': u'0c2f16c954cd2cafccfaf1bf50000ac6'}, u'success': True}
I need to use the random collection of letters/numbers in the single quote 0c2f16c954cd2cafccfaf1bf50000ac6
(it changes every time). I dont see any double quotes in this response. So a few questions:
Upvotes: 1
Views: 55
Reputation: 57610
I dont see any double quotes in the response. Is this still json?
It was JSON. r.json()
deserialized the JSON response to a Python dict
, and then print
printed that dict
.
What would be the best way to assign that middle part of random characters to a variable so I can use it in a request url I need to build next?
a_variable = r.json()["data"]["stok"]
Upvotes: 3