alfem/telegram-download-daemon

Cannot use socks5 proxy

Closed this issue · 6 comments

Gowee commented

Hi.

When I try to apply socks5 proxy with:

# Edit these lines:
proxy = {
    'proxy_type': 'socks5', # (mandatory) protocol to use (see above)
    'addr': '1.2.4.8',      # (mandatory) proxy IP address
    'port': 65535,           # (mandatory) proxy port number
    'username': 'foo',      # (optional) username if the proxy requires auth
    'password': 'bar',      # (optional) password if the proxy requires auth
    'rdns': True            # (optional) whether to use remote or local resolve, default remote
}

, the container exits with:

Traceback (most recent call last):
  File "/app/./telegram-download-daemon.py", line 178, in <module>
    proxy=proxy).start() as client:
  File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 133, in start
    else self.loop.run_until_complete(coro)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 140, in _start
    await self.connect()
  File "/usr/local/lib/python3.10/site-packages/telethon/client/telegrambaseclient.py", line 525, in connect
    if not await self._sender.connect(self._connection(
  File "/usr/local/lib/python3.10/site-packages/telethon/network/mtprotosender.py", line 127, in connect
    await self._connect()
  File "/usr/local/lib/python3.10/site-packages/telethon/network/mtprotosender.py", line 227, in _connect
    connected = await self._try_connect(attempt)
  File "/usr/local/lib/python3.10/site-packages/telethon/network/mtprotosender.py", line 277, in _try_connect
    await self._connection.connect(timeout=self._connect_timeout)
  File "/usr/local/lib/python3.10/site-packages/telethon/network/connection/connection.py", line 244, in connect
    await self._connect(timeout=timeout, ssl=ssl)
  File "/usr/local/lib/python3.10/site-packages/telethon/network/connection/connection.py", line 225, in _connect
    sock = await self._proxy_connect(
  File "/usr/local/lib/python3.10/site-packages/telethon/network/connection/connection.py", line 110, in _proxy_connect
    parsed = self._parse_proxy(**self._proxy)
  File "/usr/local/lib/python3.10/site-packages/telethon/network/connection/connection.py", line 92, in _parse_proxy
    from socks import SOCKS5, SOCKS4, HTTP
ModuleNotFoundError: No module named 'socks'
alfem commented

Try to log into your container, and issue this command:

pip install socks

launch again the script /app/./telegram-download-daemon.py and tell me if it works, please

Gowee commented

Hi, alfem.

Thanks for the advice. But it appears to be impossible to log into the container after it crashed. I managed to fix it by executing pip install pysocks with subprocess in .py file.

alfem commented

Did it work? I can add that dependency to Dockerfile if needed.

Gowee commented

Yes, it works. It is listed here as an optional dependency https://github.com/LonamiWebs/Telethon/blob/master/optional-requirements.txt. I think it is good to add it, because it is not easy to fix manually.

alfem commented

New docker image in the way!

Gowee commented

Thanks! 🙂