How can i get needed value, because i send post request to other site and cant edit answer from site.
I have this dict from responded content:
{'username': 'DeadFinder', 'subscriptions': [{'subscription': 'default', 'expiry': '1635683460'}], 'ip': 'not at this life'}
How you can see in this dict there is a key subscriptions
, i’m need value expiry
(this is timestamp) but how can i get this value if when i’m trying to call this value i’m not see any results (code not gives needed value), maybe any variants how to get this value? I’m not finded anything like this.
Maybe my small part of code can smally help you but i doubt.
data1 = {f"hwid":"", "type":"login", "username": {username}, "pass": {password}, "sessionid":f"{response_cut2}", "name":"test_app", "ownerid":"5OLbm5S3fS"} url1 = "nope" response1 = requests.post(url1, data1) data = response1.json() #get = data.get('expiry') file_write = open("test.txt", "w") file_write.write(str(data)) file_write.close() for key in data.keys(): if key == 'info': print (data[key])
Advertisement
Answer
Are you trying to achieve this as result ?
data = {'username': 'DeadFinder', 'subscriptions': [{'subscription': 'default', 'expiry': '1635683460'}], 'ip': 'not at this life'} print(data['subscriptions'][0]['expiry']) # first get 'subscriptions' which returns an array, # so use [0] to get this dict {'subscription': 'default', 'expiry': '1635683460'} # then get 'expiry'
EDIT : In case subscriptions has multiple values then use for loop
subscriptions = data['subscriptions'] for subscription in subscriptions: print(subscription['expiry'])
Output
1635683460