Lazo Lab Sign up

App 4: Weather App with a Real API / Build the weather app

Lesson 3 of 10

Your first request

requests.get fetches a URL. Check the status code (200 means OK), then .json() turns the response into Python dictionaries.

Key points

  • Always set a timeout
  • raise_for_status() turns errors into exceptions
  • .json() gives a dict
import requests

url = "https://api.open-meteo.com/v1/forecast"
params = {"latitude": 29.37, "longitude": 47.98, "current": "temperature_2m,wind_speed_10m"}
r = requests.get(url, params=params, timeout=10)
r.raise_for_status()
data = r.json()
print(data["current"])

Your turn

Run the request and print the whole data dictionary to see what's inside.

Watch a video on thisOpens YouTube search results for “Your first request” in a new tab

Quiz · +10 XP

What status code means the request worked?

Log in to save progress and earn XP.