You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any suggestion for handle network lost connection and logging properly?
My system has regular router reboot and every time the program with throws some messy trace back message. I am no expert in those details but would like to add some try/except to get rid of those messages and replace it with something that shows there is network connection lost.
In the sample I saw this but I don't think it helps in this case.
Some example of error messages I got is as follows.
Traceback (most recent call last):
File "/mnt/d11/venv/lib/python3.11/site-packages/anyio/_core/_sockets.py", line 190, in connect_tcp
addr_obj = ip_address(remote_host)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/ipaddress.py", line 54, in ip_address
raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
ValueError: 'api.telegram.org' does not appear to be an IPv4 or IPv6 address
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
yield
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 114, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/anyio/_core/_sockets.py", line 193, in connect_tcp
gai_res = await getaddrinfo(
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request
raise exc
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request
response = await connection.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 92, in handle_async_request
raise exc
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 69, in handle_async_request
stream = await self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 117, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp
return await self._backend.connect_tcp(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 112, in connect_tcp
with map_exceptions(exc_map):
File "/usr/lib/python3.11/contextlib.py", line 155, in exit
self.gen.throw(typ, value, traceback)
File "/mnt/d11/venv/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/request/_httpxrequest.py", line 219, in do_request
res = await self._client.request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_client.py", line 1530, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_client.py", line 1617, in send
response = await self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
response = await self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
response = await self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_client.py", line 1719, in _send_single_request
response = await transport.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
with map_httpcore_exceptions():
File "/usr/lib/python3.11/contextlib.py", line 155, in exit
self.gen.throw(typ, value, traceback)
File "/mnt/d11/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/ext/_updater.py", line 628, in _network_loop_retry
if not await action_cb():
^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/ext/_updater.py", line 333, in polling_action_cb
raise exc
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/ext/_updater.py", line 322, in polling_action_cb
updates = await self.bot.get_updates(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/ext/_extbot.py", line 553, in get_updates
updates = await super().get_updates(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/_bot.py", line 394, in decorator
result = await func(self, *args, **kwargs) # skipcq: PYL-E1102
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/_bot.py", line 3542, in get_updates
await self._post(
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/_bot.py", line 482, in _post
return await self._do_post(
^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/ext/_extbot.py", line 335, in _do_post
return await super()._do_post(
^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/_bot.py", line 510, in _do_post
return await request.post(
^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/request/_baserequest.py", line 168, in post
result = await self._request_wrapper(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/request/_baserequest.py", line 288, in _request_wrapper
raise exc
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/request/_baserequest.py", line 278, in _request_wrapper
code, payload = await self.do_request(
^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/d11/venv/lib/python3.11/site-packages/telegram/request/_httpxrequest.py", line 243, in do_request
raise NetworkError(f"httpx.{err.class.name}: {err}") from err
telegram.error.NetworkError: httpx.ConnectError: [Errno -2] Name or service not known
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there any suggestion for handle network lost connection and logging properly?
My system has regular router reboot and every time the program with throws some messy trace back message. I am no expert in those details but would like to add some try/except to get rid of those messages and replace it with something that shows there is network connection lost.
In the sample I saw this but I don't think it helps in this case.
Some example of error messages I got is as follows.
Beta Was this translation helpful? Give feedback.
All reactions