n3d1117 / chatgpt-telegram-bot

🤖 A Telegram bot that integrates with OpenAI's official ChatGPT APIs to provide answers, written in Python
GNU General Public License v2.0
2.96k stars 1.36k forks source link

Error bot at startup #522

Open alexpotbitweb opened 7 months ago

alexpotbitweb commented 7 months ago

Hi there!

I have a problem with bot:

  1. docker pull n3d1117/chatgpt-telegram-bot:latest

  2. i edited .env file params OPENAI_API_KEY, TELEGRAM_BOT_TOKEN, ADMIN_USER_IDS, ALLOWED_TELEGRAM_USER_IDS

  3. then type: docker run -it --env-file .env n3d1117/chatgpt-telegram-bot

and see error:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 189, in connect_tcp addr_obj = ip_address(remote_host) File "/usr/local/lib/python3.9/ipaddress.py", line 53, 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 "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 114, in connect_tcp stream: anyio.abc.ByteStream = await anyio.connect_tcp( File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 192, in connect_tcp gai_res = await getaddrinfo( asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions yield File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 121, in connect_tcp stream._raw_socket.setsockopt(*option) # type: ignore[attr-defined] # pragma: no cover File "/usr/local/lib/python3.9/site-packages/anyio/_core/_tasks.py", line 119, in exit raise TimeoutError TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions yield File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request resp = await self._pool.handle_async_request(req) File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request raise exc File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request response = await connection.handle_async_request(request) File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 92, in handle_async_request raise exc File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 69, in handle_async_request stream = await self._connect(request) File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 117, in _connect stream = await self._network_backend.connect_tcp(*kwargs) File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp return await self._backend.connect_tcp( File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 121, in connect_tcp stream._raw_socket.setsockopt(option) # type: ignore[attr-defined] # pragma: no cover File "/usr/local/lib/python3.9/contextlib.py", line 137, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/telegram/request/_httpxrequest.py", line 216, in do_request res = await self._client.request( File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects response = await self._send_single_request(request) File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1719, in _send_single_request response = await transport.handle_async_request(request) File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request resp = await self._pool.handle_async_request(req) File "/usr/local/lib/python3.9/contextlib.py", line 137, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/app/bot/main.py", line 117, in main() File "/app/bot/main.py", line 113, in main telegram_bot.run() File "/app/bot/telegram_bot.py", line 1084, in run application.run_polling() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 727, in run_polling return self.run( File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 921, in __run raise exc File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 910, in run loop.run_until_complete(self.initialize()) File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 399, in initialize await self.bot.initialize() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_extbot.py", line 271, in initialize await super().initialize() File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 591, in initialize await self.get_me() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_extbot.py", line 1706, in get_me return await super().get_me( File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 381, in decorator result = await func(self, *args, **kwargs) # skipcq: PYL-E1102 File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 736, in get_me result = await self._post( File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 469, in _post return await self._do_post( File "/usr/local/lib/python3.9/site-packages/telegram/ext/_extbot.py", line 325, in _do_post return await super()._do_post( File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 497, in _do_post return await request.post( File "/usr/local/lib/python3.9/site-packages/telegram/request/_baserequest.py", line 168, in post result = await self._request_wrapper( File "/usr/local/lib/python3.9/site-packages/telegram/request/_baserequest.py", line 291, in _request_wrapper raise exc File "/usr/local/lib/python3.9/site-packages/telegram/request/_baserequest.py", line 277, in _request_wrapper code, payload = await self.do_request( File "/usr/local/lib/python3.9/site-packages/telegram/request/_httpxrequest.py", line 233, in do_request raise TimedOut from err telegram.error.TimedOut: Timed out

what i do wrong ? please help

yurnov commented 7 months ago

It seems you don't have an internet connection in your docker network. Try to restart docker with something like sudo systemctl restart dockerd and test your connection with docker run -it --rm docker.io/library/alpine:latest ping -c 5 google.com.

More about docker networking is here

alexpotbitweb commented 7 months ago

thanks for reply!

everything seems to be fine with the network

docker run -it --rm docker.io/library/alpine:latest ping -c 5 google.com

PING google.com (142.250.186.206): 56 data bytes 64 bytes from 142.250.186.206: seq=0 ttl=117 time=27.687 ms 64 bytes from 142.250.186.206: seq=1 ttl=117 time=27.061 ms 64 bytes from 142.250.186.206: seq=2 ttl=117 time=26.057 ms 64 bytes from 142.250.186.206: seq=3 ttl=117 time=24.964 ms 64 bytes from 142.250.186.206: seq=4 ttl=117 time=27.042 ms --- google.com ping statistics --- 5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max = 24.964/26.562/27.687 ms

docker run -it --env-file .env n3d1117/chatgpt-telegram-bot

Unable to find image 'n3d1117/chatgpt-telegram-bot:latest' locally latest: Pulling from n3d1117/chatgpt-telegram-bot 661ff4d9561e: Pull complete 44cda88cd45d: Pull complete 0ee71d022571: Pull complete 2738858d84c0: Pull complete faa411d0fa85: Pull complete 94e796d3ed38: Pull complete 7cbd88c2fdec: Pull complete 5f8bd8140c68: Pull complete d6be7a1806d2: Pull complete Digest: sha256:1b6a05e489d7ffd213924ce314a30f2032d1d2cb51baf9c6b081273b3f5ffeb6 Status: Downloaded newer image for n3d1117/chatgpt-telegram-bot:latest Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 114, in connect_tcp stream: anyio.abc.ByteStream = await anyio.connect_tcp( File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 221, in connect_tcp await event.wait() File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 597, in aexit raise exceptions[0] File "/usr/local/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 167, in try_connect stream = await asynclib.connect_tcp(remote_host, remote_port, local_address) File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1627, in connect_tcp await get_running_loop().create_connection( File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 500, in sock_connect return await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions yield File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 121, in connect_tcp stream._raw_socket.setsockopt(*option) # type: ignore[attr-defined] # pragma: no cover File "/usr/local/lib/python3.9/site-packages/anyio/_core/_tasks.py", line 119, in exit raise TimeoutError TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions yield File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request resp = await self._pool.handle_async_request(req) File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 262, in handle_async_request raise exc File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 245, in handle_async_request response = await connection.handle_async_request(request) File "/usr/local/lib/python3.9/site-packages/httpcore/_async/http_proxy.py", line 271, in handle_async_request connect_response = await self._connection.handle_async_request( File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 92, in handle_async_request raise exc File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 69, in handle_async_request stream = await self._connect(request) File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 117, in _connect stream = await self._network_backend.connect_tcp(*kwargs) File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp return await self._backend.connect_tcp( File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 121, in connect_tcp stream._raw_socket.setsockopt(option) # type: ignore[attr-defined] # pragma: no cover File "/usr/local/lib/python3.9/contextlib.py", line 137, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/telegram/request/_httpxrequest.py", line 216, in do_request res = await self._client.request( File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects response = await self._send_single_request(request) File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1719, in _send_single_request response = await transport.handle_async_request(request) File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request resp = await self._pool.handle_async_request(req) File "/usr/local/lib/python3.9/contextlib.py", line 137, in exit self.gen.throw(typ, value, traceback) File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/app/bot/main.py", line 117, in main() File "/app/bot/main.py", line 113, in main telegram_bot.run() File "/app/bot/telegram_bot.py", line 1084, in run application.run_polling() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 727, in run_polling return self.run( File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 921, in __run raise exc File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 910, in run loop.run_until_complete(self.initialize()) File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_application.py", line 399, in initialize await self.bot.initialize() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_extbot.py", line 271, in initialize await super().initialize() File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 591, in initialize await self.get_me() File "/usr/local/lib/python3.9/site-packages/telegram/ext/_extbot.py", line 1706, in get_me return await super().get_me( File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 381, in decorator result = await func(self, *args, **kwargs) # skipcq: PYL-E1102 File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 736, in get_me result = await self._post( File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 469, in _post return await self._do_post( File "/usr/local/lib/python3.9/site-packages/telegram/ext/_extbot.py", line 325, in _do_post return await super()._do_post( File "/usr/local/lib/python3.9/site-packages/telegram/_bot.py", line 497, in _do_post return await request.post( File "/usr/local/lib/python3.9/site-packages/telegram/request/_baserequest.py", line 168, in post result = await self._request_wrapper( File "/usr/local/lib/python3.9/site-packages/telegram/request/_baserequest.py", line 291, in _request_wrapper raise exc File "/usr/local/lib/python3.9/site-packages/telegram/request/_baserequest.py", line 277, in _request_wrapper code, payload = await self.do_request( File "/usr/local/lib/python3.9/site-packages/telegram/request/_httpxrequest.py", line 233, in do_request raise TimedOut from err telegram.error.TimedOut: Timed out

Egor3f commented 4 months ago

The same problem!