我导入了一个名为“ 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()
我收到此错误:
observation = owm.weather_at_place(Cidade , ' , ' , Pais2)
TypeError: weather_at_place() takes 2 positional arguments but 4 were given
有人可以帮我吗?
答案 0 :(得分:0)
尝试只给它两个参数。
观察= owm.weather_at_place(Cidade,Pais2)
答案 1 :(得分:0)
从文档(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))
答案 2 :(得分:0)
您可以从代码中检查weather_at_place
方法:
https://github.com/csparpa/pyowm/blob/master/pyowm/weatherapi25/owm25.py#L210
def weather_at_place(self, name):
"""
Queries the OWM Weather API for the currently observed weather at the
specified toponym (eg: "London,uk")
:param name: the location's toponym
:type name: str or unicode
:returns: an *Observation* instance or ``None`` if no weather data is available
:raises: *ParseResponseException* when OWM Weather API responses' data cannot be parsed or *APICallException* when OWM Weather API can not be reached
"""
您会看到它仅接受name
作为单个字符串。
您还可以检查并遵循文档中的示例:
https://pyowm.readthedocs.io/en/latest/usage-examples-v2/weather-api-object-model.html#the-owm25-class
当前天气查询
* find current weather at a specific location ---> eg: owm.weather_at_place('London,UK')