如何解决我可以在英国开放天气地图中按邮政编码搜索吗
我根据网上找到的教程制作了一个非常简单的天气应用程序。我正在使用请求模块,我正在尝试调用英国邮政编码 GU27PG 的天气。我正在使用 https://openweathermap.org/current#zip 中的文档来构建我的 url。这是我的代码:
import requests
import configparser
def get_api_key():
config = configparser.ConfigParser()
config.read('config.ini')
return config['openweathermap']['api']
def get_weather_results(zip_code,country_code,api_key):
api_url = 'http://api.openweathermap.org/data/2.5/weather?zip={},{}&appid={}'.format(zip_code,api_key)
r = requests.get(api_url)
return r.json()
print(get_weather_results("GU27PG","UK",get_api_key()))
当我运行它时它返回这个:
{'cod': '404','message': 'city not found'}
我很确定这是一个有效的邮政编码和国家/地区代码。我曾经收到错误 401,这意味着我的 api 密钥未激活但已停止,因此我的 api 密钥肯定有效。 任何帮助将不胜感激
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。