import requests
api_url = "https://api.openweathermap.org/data/2.5/weather"
api_key = "your_api_key"
params = {"q": "London", "appid": api_key}
response = requests.get(api_url, params=params)
if response.status_code == 200:
weather_data = response.json()
print(weather_data)
else:
print("API请求出错:", response.text)
在此示例中,api_key需要替换为您自己的API密钥。同时,在请求参数中添加了appid参数来设置API密钥。请确保您的代码中也正确设置了API密钥参数。