1

Trying to make a script to read this json file and I having some erros while trying it.

urllib.request.urlopen("https://github.com/lutangar/cities.json/blob/master/cities.json") as url: data = json.load(url) print(data)

When I try to run, I'm having this error and I don't know how to fix it.

JSONDecodeError: Expecting value: line 8 column 1 (char 7)

I'm trying to open the link but I alwasy got an error message.

1 Answer 1

2

Add ?raw=true to the URL:

import urllib.request

with urllib.request.urlopen(
    "https://github.com/lutangar/cities.json/blob/master/cities.json?raw=true"
) as u:
    data = json.load(u)
    print(data)

Prints:

[{'country': 'AD', 'name': 'Sant Julià de Lòria', 'lat': '42.46372', 'lng': '1.49129'}, {'country': 'AD', 'name': 'Pas de la Casa', 'lat': '42.54277', 'lng': '1.73361'}, {'country': 'AD', 'name': 'Ordino', 'lat': '42.55623', 'lng':  ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.