UnauthorizedError Traceback (most recent call last) Cell In[162], line 11 9 # 获取上个月的天气情况 10 mgr = owm.weather_manager() ---> 11 observation = mgr.weather_at_place('上海') # 这里以北京为例 12 date_obj = datetime.datetime(last_month.year, last_month.month, 1) 13 one_call = mgr.one_call(lat=observation.weather.location.lat, lon=observation.weather.location.lon, dt=date_obj.timestamp(), exclude='current,minutely,hourly,alerts') File ~/opt/anaconda3/lib/python3.9/site-packages/pyowm/weatherapi25/weather_manager.py:53, in WeatherManager.weather_at_place(self, name) 51 assert isinstance(name, str), "Value must be a string" 52 params = {'q': name} ---> 53 _, json_data = self.http_client.get_json(OBSERVATION_URI, params=params) 54 return observation.Observation.from_dict(json_data) File ~/opt/anaconda3/lib/python3.9/site-packages/pyowm/commons/http_client.py:158, in HttpClient.get_json(self, path, params, headers) 156 except requests.exceptions.Timeout: 157 raise exceptions.TimeoutError('API call timeouted') --> 158 HttpClient.check_status_code(resp.status_code, resp.text) 159 try: 160 return resp.status_code, resp.json() File ~/opt/anaconda3/lib/python3.9/site-packages/pyowm/commons/http_client.py:313, in HttpClient.check_status_code(cls, status_code, payload) 311 raise exceptions.APIRequestError(payload) 312 elif status_code == 401: --> 313 raise exceptions.UnauthorizedError('Invalid API Key provided') 314 elif status_code == 404: 315 raise exceptions.NotFoundError('Unable to find the resource')解释下是什么原因的报错
时间: 2024-04-27 10:23:56 浏览: 290
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个报错是因为你提供的OpenWeatherMap API Key无效或者过期了。在OpenWeatherMap的API访问中,API Key是必须的,如果API Key无效或者过期,将无法访问OpenWeatherMap API。
请检查你的API Key是否正确并且有效。你可以在OpenWeatherMap的官方网站上登录账户并获取新的API Key。
另外,如果你确定API Key是正确的,但是仍然出现这个报错,可能是因为你的API Key没有足够的权限或者OpenWeatherMap的API出现了故障。你可以等待一段时间再试,或者联系OpenWeatherMap的支持团队寻求帮助。
阅读全文