-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api2.py
More file actions
27 lines (25 loc) · 922 Bytes
/
Copy pathtest_api2.py
File metadata and controls
27 lines (25 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
import sys
print("Testing HeWeather API...")
url = 'https://geoapi.qweather.com/v2/city/lookup'
params = {'location': '北京', 'key': 'cfb037bde7de452e8c5f8b15d741fb31', 'lang': 'zh'}
try:
r = requests.get(url, params=params, timeout=10)
print('Status:', r.status_code)
print('Headers:', r.headers)
print('Response body:', r.text[:500])
if r.status_code != 200:
print('Full response:', r.text)
except Exception as e:
print('Error:', e)
import traceback
traceback.print_exc()
print("\n--- Testing weather now with known location ID ---")
url2 = 'https://devapi.qweather.com/v7/weather/now'
params2 = {'location': '101010100', 'key': 'cfb037bde7de452e8c5f8b15d741fb31', 'lang': 'zh'}
try:
r2 = requests.get(url2, params=params2, timeout=10)
print('Status:', r2.status_code)
print('Response:', r2.text[:500])
except Exception as e:
print('Error:', e)