【发布时间】:2021-03-23 17:58:59
【问题描述】:
我研究了 PyOWM 和 OWM API 指南以及一些代码配方,并且在大量代码中可以正常工作,但我就是不知道如何获取今天预报的当前天气图标?这是一个与图标不同的代码 sn-p:
from pyowm.owm import OWM
from pyowm.utils import timestamps
import requests, json
def checkInternetRequests(url='http://www.google.com/', timeout=3):
try:
r = requests.head(url, timeout=timeout)
return True
except requests.ConnectionError as ex:
print(ex)
return False
def get_weather():
if checkInternetRequests() == True:
# 52.5766° N, 1.5438° W
print ("Internet Up")
CITY = "Atherstone, GB"
LON = 1.54
LAT = 52.576
API_KEY = "myapikey"
ICON_URL_1 = "http://openweathermap.org/img/wn/"
ICON_URL_2 = "@2x.png"
owm = OWM(API_KEY)
mgr = owm.weather_manager()
one_call = mgr.one_call(lat=LAT, lon=LON)
print (one_call.forecast_hourly[3]) #works - 3hrs from now
print ("===========================")
print (one_call.forecast_daily[0]) # works - Today
print ("===========================")
print (one_call.forecast_daily[0].weather.icon)
else:
print ("Internet Down")
time.sleep(10)
get_weather()
我收到以下错误:
Traceback (most recent call last):
File "weather1.py", line 37, in <module>
get_weather()
File "weather1.py", line 31, in get_weather
print (one_call.forecast_daily[0].weather.icon)
AttributeError: 'Weather' object has no attribute 'weather'
我哪里错了?谢谢!
【问题讨论】: