本帖最后由 LeeTien 于 2018-5-12 09:04 编辑
参照蓝火帖子改造:https://bbs.hassbian.com/forum.p ... =%E5%A4%A9%E6%B0%94
添加今天天气数据,配置运行没有问题却无法获取数据,何故?
配置如下:
略
self._forecast_url = "https://free-api.heweather.com/s6/weather/forecast?parameters"
略
#今天天气预报
try:
r_forecast = requests.get(self._forecast_url, self._params, verify=True, headers=self._headers)
con_forecast = r_forecast.json()
self._day0_cond_txt = con_forecast["HeWeather6"][0]["daily_forecast"][0]["cond_txt_d"]
self._day0_hum = con_forecast["HeWeather6"][0]["daily_forecast"][0]["hum"]
self._day0_pcpn = con_forecast["HeWeather6"][0]["daily_forecast"][0]["pcpn"]
self._day0_pres = con_forecast["HeWeather6"][0]["daily_forecast"][0]["pres"]
self._day0_tmp_max = con_forecast["HeWeather6"][0]["daily_forecast"][0]["tmp_max"]
self._day0_tmp_min = con_forecast["HeWeather6"][0]["daily_forecast"][0]["tmp_min"]
self._day0_vis = con_forecast["HeWeather6"][0]["daily_forecast"][0]["vis"]
self._day0_wind_spd = con_forecast["HeWeather6"][0]["daily_forecast"][0]["wind_spd"]
self._day0_wind_sc = con_forecast["HeWeather6"][0]["daily_forecast"][0]["wind_sc"]
self._day0_wind_dir = con_forecast["HeWeather6"][0]["daily_forecast"][0]["wind_dir"]
except:
_LOGGER.info("今天天气连接失败".join(con_forecast))
|