我想获得 Yandex Weather 请求的回复。
我根据 Yandex Weather API 文档编写了一个请求:https://yandex.ru/dev/weather/doc/ru/concepts/forecast-info#req-ex
我在同一个 Yandex Weather API 网站上获得了一个临时访问密钥,它仍然有效。
我使用 geopy 库获取了一个城市的坐标。我通过 get 请求中的 f 字符串传递这些坐标,并且还使用从 API 站点获取的请求中的标头。
我不明白为什么我最终得到:
{"message":"forbidden"}
from geopy.geocoders import Nominatim
import requests
access_key = 'd4253969-73e2-4ef8-9932-631053b02222'
city = input('Введите название города (латиницей), в котором вы хотите узнать погоду: ')
headers = {"X-Yandex-Weather-Key":"d4253969-73e2-4ef8-9932-631053b02222"}
def get_coordinates(city_name):
loc = Nominatim(user_agent="GetLoc")
getLoc = loc.geocode(city_name)
return [getLoc.latitude, getLoc.longitude]
coordinates = get_coordinates(city)
print(f'Координаты: {coordinates}')
url = f'https://api.weather.yandex.ru/v2/informers?lat={coordinates[0]}&lon={coordinates[1]}'
response = requests.get(url, headers=headers)
print(response.text)