Menu
Coddy logo textTech

GET Request to Server

Coddy'nin Python ile API kursunda ders 9 / 10.

challenge icon

Görev

Orta

Bir API ile düzgün bir bağlantı kurduğunuza göre, belirli bir konum için bir GET isteği gönderelim.

  1. Şu adrese bir GET isteği gönderin: https://wttr.in/London?format=j1 (?format=j1 kısmı servise JSON döndürmesini söyler)
  2. requests.get() nesnesini response adlı bir değişkene kaydedin
  3. response.json() kullanarak yanıtı ayrıştırın ve data adlı bir değişkene kaydedin
  4. Mevcut koşullar data["current_condition"][0] içinde yer alır. Sıcaklığı (temp_C) ve açıklamayı (weatherDesc[0]["value"]) çekip çıkarın, ardından her ikisini de yazdırın

Kendin dene

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"])

Python ile API bölümündeki tüm dersler