GET Request to Server
Coddy'nin Python ile API kursunda ders 9 / 10.
Görev
OrtaBir API ile düzgün bir bağlantı kurduğunuza göre, belirli bir konum için bir GET isteği gönderelim.
- Şu adrese bir GET isteği gönderin:
https://wttr.in/London?format=j1(?format=j1kısmı servise JSON döndürmesini söyler) requests.get()nesnesiniresponseadlı bir değişkene kaydedinresponse.json()kullanarak yanıtı ayrıştırın vedataadlı bir değişkene kaydedin- 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
3Weather Fetch API Program
API Connection to ServerGET Request to ServerDisplaying Appropriate Results