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

Timed out #489

Open HumanRightOn opened 8 months ago

HumanRightOn commented 8 months ago

The server is located in Russia, so now I have to use a proxy bot to work - the bot can ignore the message, giving the following error: 2023-12-11 22:17:23,148 - root - ERROR - Timed out Traceback (most recent call last): File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\anyio_core_sockets.py", line 190, in connect_tcp addr_obj = ip_address(remote_host) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\AppData\Local\Programs\Python\Python311\Lib\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 "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\anyio_core_tasks.py", line 115, in fail_after yield cancel_scope File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_backends\anyio.py", line 114, in connect_tcp stream: anyio.abc.ByteStream = await anyio.connect_tcp( ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\anyio_core_sockets.py", line 193, in connect_tcp gai_res = await getaddrinfo( ^^^^^^^^^^^^^^^^^^ asyncio.exceptions.CancelledError: Cancelled by cancel scope 19d638f9b50

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_backends\anyio.py", line 113, in connect_tcp with anyio.fail_after(timeout): File "C:\Users\Server\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\anyio_core_tasks.py", line 118, in fail_after raise TimeoutError TimeoutError

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

Traceback (most recent call last): File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_transports\default.py", line 60, in map_httpcore_exceptions yield File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_transports\default.py", line 353, in handle_async_request resp = await self._pool.handle_async_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_async\connection_pool.py", line 262, in handle_async_request raise exc File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_async\connection_pool.py", line 245, in handle_async_request response = await connection.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_async\connection.py", line 92, in handle_async_request raise exc File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_async\connection.py", line 69, in handle_async_request stream = await self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_async\connection.py", line 117, in _connect stream = await self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_backends\auto.py", line 31, in connect_tcp return await self._backend.connect_tcp( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpcore_backends\anyio.py", line 112, in connect_tcp with map_exceptions(exc_map): File "C:\Users\Server\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\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 "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\request_httpxrequest.py", line 216, in do_request res = await self._client.request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_client.py", line 1617, in send response = await self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_client.py", line 1682, in _send_handling_redirects response = await self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_client.py", line 1719, in _send_single_request response = await transport.handle_async_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\httpx_transports\default.py", line 352, in handle_async_request with map_httpcore_exceptions(): File "C:\Users\Server\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 155, in exit self.gen.throw(typ, value, traceback) File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\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 "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\bot\telegram_bot.py", line 395, in prompt await update.effective_message.reply_chat_action( File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram_message.py", line 2162, in reply_chat_action return await self.get_bot().send_chat_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\ext_extbot.py", line 2283, in send_chat_action return await super().send_chat_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram_bot.py", line 381, in decorator result = await func(self, *args, **kwargs) # skipcq: PYL-E1102 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram_bot.py", line 2702, in send_chat_action return await self._post( ^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram_bot.py", line 469, in _post return await self._do_post( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\ext_extbot.py", line 325, in _do_post return await super()._do_post( ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram_bot.py", line 497, in _do_post return await request.post( ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\request_baserequest.py", line 168, in post result = await self._request_wrapper( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\request_baserequest.py", line 291, in _request_wrapper raise exc File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\request_baserequest.py", line 277, in _request_wrapper code, payload = await self.do_request( ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Server\Desktop\chatgpt-telegram-bot-0.3.1\venv\Lib\site-packages\telegram\request_httpxrequest.py", line 233, in do_request raise TimedOut from err telegram.error.TimedOut: Timed out

Perhaps using a proxy in .env could help solve this problem, but I haven't learned how to work with it yet either. He also does not want to take an ip proxy with a username and password from the line and simply does not work, gives errors identical to working directly from the Russian ip, he probably does not use a proxy at this moment

Jipok commented 8 months ago

Use `qutes` for logs, without it hard to read. Openai does not officially support work from Russia. Just a small flaw that until recently the API was accessible from Russian IPs, now it has been fixed. So you'll have to use a proxy. This is easy to do by adding a line like this to env: OPENAI_PROXY=http://127.0.0.1:25345

ilyavpro commented 6 months ago

Use qutes for logs, without it hard to read. Openai does not officially support work from Russia. Just a small flaw that until recently the API was accessible from Russian IPs, now it has been fixed. So you'll have to use a proxy. This is easy to do by adding a line like this to env: OPENAI_PROXY=http://127.0.0.1:25345

Good afternoon! Can you please help if it's not too much trouble. I installed everything according to the manual before step 4 (python bot/main.py ). I introduced telegram and openai APIs into env, and also installed (OPENAI_PROXY=http://127.0.0.1:25345). However, I still get a blocking message because my server is located in Russia. Could you tell me if I should create my proxy in some other way? Do I need to follow the steps with Docker Compose from the readme? I am not well versed in the topic of network connections, and I could not find an exhaustive answer in the discussion section. Thanks!

Jipok commented 6 months ago

OPENAI_PROXY=http://127.0.0.1:25345/ это конкретный пример и если у тебя локально не запущено что-то на 25345 порту, что-то что предоставляет http прокси на зарубежный сервер, то толку от этой опции нет. Тебе нужен прокси через который будет доступен OpenAI. Т.е. не российский сервер или vpn. Ну или изначально запускать бота на сервере не из России. Я использую опцию OPENAI_PROXY и утилиту https://github.com/pufferffish/wireproxy чтобы пробросить только запросы к OpenAI через мой основной WireGuard VPN