Menu
Coddy logo textTech

GET Request to Server

Lesson 9 of 10 in Coddy's API in Python course.

challenge icon

Challenge

Medium

Now that you've established a proper connection with an API, let's send a GET request for a specific location.

  1. Send a GET request to: https://wttr.in/London?format=j1 (the ?format=j1 part tells the service to return JSON)
  2. Save the requests.get() object to a variable called response
  3. Parse the response using response.json() and save it to a variable called data
  4. The current conditions live inside data["current_condition"][0]. Pull out the temperature (temp_C) and the description (weatherDesc[0]["value"]), then print both

Try it yourself

import requests

# Step 1: Send GET request for London weather (j1 = JSON format)
response = # Your code here

# Step 2: Parse JSON response
data = # Your code here

# Step 3: Print weather information
current = data["current_condition"][0]
print("Temperature:", current["temp_C"], "°C")
print("Description:", current["weatherDesc"][0]["value"])

All lessons in API in Python