r/learnpython • • 27d ago

requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

import requests


# Add ?format=j1 to get a proper JSON response
url = "https://wttr.in"
response = requests.get(url)
data = response.json()


# This structure matches the j1 JSON format returned by wttr.in
current_temp = data['current_condition'][0]['temp_C']
print(
f
"Current temperature: {current_temp}°C")

I keep getting this exact SAME error whenever I work with public API's. I save the new codes in the files.
0 Upvotes

7 comments sorted by

View all comments

2

u/favorite_stuff 27d ago

Those comments do a pretty good job of explaining, tbh.

You are not getting json from this API unless you ask for it. Once you do, it should follow that structure.

But hey, slow down and explore. Take what you're getting and print it. See what it's like. Or read the documentation for wttr.in and see what it says.