Menu
Coddy logo textTech
flag Ar iconالعربيةdown icon

GET Request to Server

الدرس 9 من 10 في دورة API في Python على Coddy.

challenge icon

التحدي

متوسط

الآن بعد أن قمت بإنشاء اتصال صحيح بواجهة برمجة التطبيقات (API)، فلنرسل طلب GET لموقع محدد.

  1. أرسل طلب GET إلى: https://wttr.in/London?format=j1 (الجزء ?format=j1 يخبر الخدمة بإرجاع JSON)
  2. احفظ كائن requests.get() في متغير يسمى response
  3. قم بتحليل الاستجابة باستخدام response.json() واحفظها في متغير يسمى data
  4. توجد الظروف الحالية داخل data["current_condition"][0]. استخرج درجة الحرارة (temp_C) والوصف (weatherDesc[0]["value"])، ثم اطبعهما معاً

جرّب بنفسك

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

جميع دروس API في Python