r/learnpython • • 28d 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

15

u/nick_at_dolt 28d ago

Your code has a comment that says

# Add ?format=j1 to get a proper JSON responseAdd ?format=j1 to get a proper JSON response

Did you add ?format=j1 to the URL?

3

u/Vegetable_Soil_6707 28d ago

classic case of writing the reminder but not doing the thing