Reputation: 3
I need to get a key value of HttpResponse
from some URL and send the value again to the url to get some results through Restapi
resp = requests.get('https://someurl.io')
data = HttpResponse(resp)
return data
with this code i got a response like,
{"status":200,"result":{"postcode":"BN14 9GB","quality":1,"eastings":515087,"northings":105207,"country":"England","nhs_ha":"South East Coast","longitude":-0.36701,"latitude":50.834955,"european_electoral_region":"South East","primary_care_trust":"West Sussex","admin_ward":"Offington","ced":"Cissbury","ccg":"NHS Coastal West Sussex","nuts":"West Sussex (South West)","codes":{"admin_district":"E07000229","admin_county":"E10000032","admin_ward":"E05007703","parish":"E43000150","parliamentary_constituency":"E14000682","ccg":"E38000213","ced":"E58001617","nuts":"UKJ27"}}}
I have to send only the latitude and longitude value to some URL and get results. I would like to do this in rest api. I dont know how to get only latitude and longitude value and through the value how to get response from someurl.io.
Upvotes: 0
Views: 3592
Reputation: 476699
You can obtain a Python dictionary with data.json()
, and then do some processing to construct a new dictionary, like:
resp = requests.get('https://someurl.io')
resp_data = resp.json()['result']
result_dic = {
'longitude': resp_data['longitude'],
'latitude': resp_data['latitude']
}
# ...
You can for example return the dictionary as:
return JsonResponse(result_dic)
and this will thus contain a dictionary with two keys: 'longitude'
and 'latitude'
. You can of course pass other values as well.
Upvotes: 1