Skip to content

Commit

Permalink
pcp-geolocate: make it work with older versions of python
Browse files Browse the repository at this point in the history
Avoids "TypeError: the JSON object must be str, not 'bytes'" with
(at least) python 3.5 and 2.7.
  • Loading branch information
natoscott committed Nov 27, 2023
1 parent 186bfff commit efb9dda
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pcp/geolocate/pcp-geolocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def finish(url):

def ipinfo(url):
with httprequest.urlopen(url) as http:
data = json.load(http)
js = http.read().decode('utf-8')
data = json.loads(js)
coords = data['loc'].split(',')
print(output % (coords[0], coords[1]))
finish(url)
Expand All @@ -73,7 +74,8 @@ def ipinfo(url):

def mozilla(url):
with httprequest.urlopen(url) as http:
data = json.load(http)
js = http.read().decode('utf-8')
data = json.loads(js)
coords = data['location']
print(output % (coords['lat'], coords['lng']))
finish(url)
Expand Down

0 comments on commit efb9dda

Please sign in to comment.