我导入了一个名为“pyown”的库来使用python进行本地化,我还安装了另一个库,它调用请求来获取气象数据。在
我的剧本:
import pyown
import requests
res = requests.get('https://ipinfo.io/')
data = res.json()
Cidade = str(data['city'])
Pais = str(data['country'])
Pais2 = Pais.lower()
observation = owm.weather_at_place(Cidade , ',' , Pais2)
w = observation.get_weather()
temperature = w.get_temperature('celsius')
wind = w.get_wind()
我有个错误:
^{pr2}$有人能帮我吗?在
试着只给它2个参数。在
观察=哦,天气预报(Cidade,Pais2)
您可以从代码中检查
weather_at_place
方法: https://github.com/csparpa/pyowm/blob/master/pyowm/weatherapi25/owm25.py#L210您可以看到它只接受
name
作为单个字符串。在您也可以查看并遵循文档中的示例:
https://pyowm.readthedocs.io/en/latest/usage-examples-v2/weather-api-object-model.html#the-owm25-class
从文档(https://buildmedia.readthedocs.org/media/pdf/pyowm/latest/pyowm.pdf)来看,您希望将城市和国家作为一个字符串。尝试类似于:
observation = owm.weather_at_place(Cidade + ',' + Pais2)
或者
observation = owm.weather_at_place('{},{}'.format(Cidade, Pais2))
相关问题 更多 >
编程相关推荐