Dolphino
@Dolphino

В первый раз пытаюсь написать программу на питоне(про погоду) и выпадает такая ошибка, что делать?

Traceback (most recent call last):
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\util\connection.py", line 95, in create_connection
raise err
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\util\connection.py", line 85, in create_connection
sock.connect(sa)
TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connection.py", line 358, in connect
self.sock = conn = self._new_conn()
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connection.py", line 179, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (, 'Connection to api.openweathermap.org timed out. (connect timeout=5)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.openweathermap.org', port=443): Max retries exceeded with url: /data/2.5/weather?APPID=5d784a19075531d4a77491650dc461b6&lang=en&q=New+York%2C+USA (Caused by ConnectTimeoutError(, 'Connection to api.openweathermap.org timed out. (connect timeout=5)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\pyowm\commons\http_client.py", line 149, in get_json
resp = self.http.get(url, params=params, headers=headers, proxies=proxies,
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\requests\adapters.py", line 507, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.openweathermap.org', port=443): Max retries exceeded with url: /data/2.5/weather?APPID=5d784a19075531d4a77491650dc461b6&lang=en&q=New+York%2C+USA (Caused by ConnectTimeoutError(, 'Connection to api.openweathermap.org timed out. (connect timeout=5)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\galki\main.py", line 7, in
observation = mgr.weather_at_place(city)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\pyowm\weatherapi25\weather_manager.py", line 53, in weather_at_place
_, json_data = self.http_client.get_json(OBSERVATION_URI, params=params)
File "C:\Users\galki\AppData\Roaming\Python\Python310\site-packages\pyowm\commons\http_client.py", line 155, in get_json
raise exceptions.InvalidSSLCertificateError(str(e))
pyowm.commons.exceptions.InvalidSSLCertificateError: HTTPSConnectionPool(host='api.openweathermap.org', port=443): Max retries exceeded with url: /data/2.5/weather?APPID=5d784a19075531d4a77491650dc461b6&lang=en&q=New+York%2C+USA (Caused by ConnectTimeoutError(, 'Connection to api.openweathermap.org timed out. (connect timeout=5)'))

Вот сам код
import eel
import pyowm
from pyowm import OWM
city = "New York, USA"
owm = pyowm.OWM('5d784a19075531d4a77491650dc461b6')
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
temp = w.temperature('celcius')['temp']

print("В городе" + city + "сейчас" + str(temp) + "градусов")
  • Вопрос задан
  • 926 просмотров
Пригласить эксперта
Ответы на вопрос 4
Connection to api.openweathermap.org timed out
Не удалось соединиться с api.openweathermap.org и по таймауту соединение было закрыто. В браузере эта ссылка открываетя?
Ответ написан
Комментировать
AgentSmith
@AgentSmith
Это мой правильный ответ на твой вопрос
У меня этот кода работает, но нужно удалить неиспользуемую библиотеку eel.
Timeout говорит о том, что нет соединения с сервером. Проверь, может файрволл отрубает соединение, либо отлуп на уровне провайдера. Попробуй через прокси или vpn
Ответ написан
Комментировать
@CodeOrNotCode
Этот код для старой версии модуля
Попробуй удалить переменную mgr
И присвоить observation = owm.weather_at_place(city)
И w = observation.get_weather()
Ответ написан
Комментировать
LencoDigitexer
@LencoDigitexer
python, боты вк телеграм, хостинг, rtl sdr
API погоды из этого модуля заблокирован - https://qna.habr.com/q/1161054
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы