0

I try to read data from the api geonames. I am using Python 3.7 This is working as it should. Now I need to convert the results, but I don't know how. This is my code:

import urllib.request
import json

#Lat & lon of Hellevoetsluis-NL
lat=51.8
lon=4.131

var = '&lat=' + str(lat)+'&lng='+str(lon)+'&username=demo'
raw = urllib.request.urlopen(url2+var, timeout=4).read(10000)
raw = urllib.request.urlopen(url2+var, timeout=4).read(1000)

this is the result

b'{"geonames": [{\n  "adminCode1": "11",\n  "lng": "4.13333",\n  "distance": "3.7119",\n  "geonameId": 2754454,\n  "toponymName": "Hellevoetsluis",\n  "countryId": "2750405",\n  "fcl": "P",\n  "population": 21927,\n  "countryCode": "NL",\n  "name": "Hellevoetsluis",\n  "fclName": "city, village,...",\n  "countryName": "Netherlands",\n  "fcodeName": "populated place",\n  "adminName1": "South Holland",\n  "lat": "51.83333",\n  "fcode": "PPL"\n}]}'

And this is what I need:

{u'geonames': [{u'distance': u'0.19394', u'countryId': u'2750405', u'name': u'Hellevoetsluis', u'countryCode': u'NL', u'geonameId': 2754454, u'toponymName': 

Thanks for any help

PowerSoft
  • 15
  • 3

0 Answers0