Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed with http proxy #509

Closed
SQLimit opened this issue Dec 23, 2023 · 3 comments
Closed

failed with http proxy #509

SQLimit opened this issue Dec 23, 2023 · 3 comments

Comments

@SQLimit
Copy link

SQLimit commented Dec 23, 2023

I'm using docker to run telebot, and I set proxy in .env file

 PROXY=http://127.0.0.1:8080

the proxy is successfully set and I test it using curl

curl -x 127.0.0.1:8080 http://myip.ipip.net

and it responded with my proxy IP
but when I run docker

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

it said

Traceback (most recent call last):
  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 1065, in create_connection
    raise exceptions[0]
  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
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 8080)

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

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 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 225, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

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.ConnectError: All connection attempts failed

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.ConnectError: All connection attempts failed

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

Traceback (most recent call last):
  File "/app/bot/main.py", line 117, in <module>
    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 240, in do_request
    raise NetworkError(f"httpx.{err.__class__.__name__}: {err}") from err
telegram.error.NetworkError: httpx.ConnectError: All connection attempts failed

it seems that it was proxy problem, beacuse I comment the proxy line in .env file, it works fine.

I have pull the latest version.

@Jipok
Copy link

Jipok commented Dec 27, 2023

Because you are running the proxy outside of the container. The container has its own network and 127.0.0.1 means the container itself. You need to either merge the networks or somehow point to the proxy outside the container. Or just use host network --network host. In any case, this is a problem with docker and its use, in no way relevant to the chatbot.

@Jipok
Copy link

Jipok commented Dec 27, 2023

I also recommend avoiding using a PROXY=. For some reason, the bot freezes with telegram through a proxy(#500). If you need to proxy only calls to openai, then use OPENAI_PROXY

@SQLimit
Copy link
Author

SQLimit commented Dec 27, 2023

The container has its own network
Thanks, I've forgotten the docker using its own network.

For some reason, the bot freezes with telegram through a proxy(#500).

I would test this and if I encounter the same problem, I will provide some info.

@SQLimit SQLimit closed this as completed Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants