keans / woice

A small python script that helps to connect to the WiFiOnICE network on ICE trains.
MIT License
4 stars 3 forks source link

`woice status` throws exceptions `socket.gaierror: [Errno -2] Name or service not known`, `requests.exceptions.ConnectionError: HTTPSConnectionPool(host='login.wifionice.de', port=443): Max retries exceeded with url: /de/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f64415fa450>: Failed to establish a new connection: [Errno -2] Name or service not known'))` and others. #7

Closed dreirund closed 11 months ago

dreirund commented 12 months ago

Ahoj,

I have installed the current git checkout of woice.

I am connected to WIFI@DB.

woice status throws Python exceptions on me. If this is due to wrong ESSID or URLs, woice should error gracefully and not throw exceptions:

woice status:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.11/site-packages/urllib3/connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f64415fa450>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.wifionice.de', port=443): Max retries exceeded with url: /de/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f64415fa450>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/woice", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/woice/woice.py", line 114, in main
    moim = WifiOnIceManager()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/woice/woice.py", line 37, in __init__
    self._get_state()
  File "/usr/lib/python3.11/site-packages/woice/woice.py", line 62, in _get_state
    r = self.s.get(LOGIN_URL, headers=HEADERS, allow_redirects=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='login.wifionice.de', port=443): Max retries exceeded with url: /de/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f64415fa450>: Failed to establish a new connection: [Errno -2] Name or service not known'))
keans commented 11 months ago

Improved error handling, if no connection can be setup.