LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!

Home Page:https://docs.telethon.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MTProxy error

lolkda opened this issue · comments

Code that causes the issue

with open(f"{config_dir}/login.json", mode="r", encoding="utf-8") as login_file:
login_set = json.load(login_file)

user_id = login_set["user_id"]
bot_token = login_set["bot_token"]
api_id = login_set["api_id"]
api_hash = login_set["api_hash"]
proxy_start = login_set["proxy_start"]
proxy_type = login_set["proxy_type"]
proxy_user = login_set.get("proxy_user")
bot_id = int(login_set["bot_token"].split(":")[0])
connectionType = connection.ConnectionTcpMTProxyRandomizedIntermediate if proxy_type == "MTProxy" else connection.ConnectionTcpFull

if proxy_start and proxy_user and proxy_type != "MTProxy":
proxy = {
"proxy_type": proxy_type,
"addr": login_set["proxy_ip"],
"port": login_set["proxy_port"],
"username": login_set["proxy_user"],
"password": login_set["proxy_password"]
}
elif proxy_start and proxy_type == "MTProxy": ## MTProxy
proxy = (login_set["proxy_ip"], login_set["proxy_port"], login_set["proxy_secret"])
elif proxy_start and proxy_type != "MTProxy":
proxy = (login_set["proxy_type"], login_set["proxy_ip"], login_set["proxy_port"])
else:
proxy = None

bot = TelegramClient(f"{path}/sessions/bot", api_id, api_hash, connection=connectionType, proxy=proxy, connection_retries=None, auto_reconnect=True, timeout=5).start(bot_token=bot_token)

Expected behavior

Normal use of MTPROTO connection

Actual behavior

Connection error using MTPROTO, sock5 and HTTP are normal

Traceback

Traceback (most recent call last):
File "/usr/local/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/lib/python3.10/runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/local/lib/python3.10/runpy.py", line 110, in _get_module_details
import(pkg_name)
File "/program/init.py", line 41, in
bot = TelegramClient(f"{path}/sessions/bot", api_id, api_hash, connection=connectionType, proxy=proxy, connection_retries=None, auto_reconnect=True, timeout=5).start(bot_token=bot_token)
File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 128, in start
else self.loop.run_until_complete(coro)
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/usr/local/lib/python3.10/site-packages/telethon/client/auth.py", line 135, in _start
await self.connect()
File "/usr/local/lib/python3.10/site-packages/telethon/client/telegrambaseclient.py", line 544, in connect
if not await self._sender.connect(self._connection(
File "/usr/local/lib/python3.10/site-packages/telethon/network/connection/tcpmtproxy.py", line 101, in init
self._secret = bytes.fromhex(proxy[2])
ValueError: non-hexadecimal number found in fromhex() arg at position 1

Telethon version

1.34

Python version

3.10

Operating system (including distribution name and version)

CentOS 7.9.2009 x86_64

Other details

No response

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

MTProxies haven't been maintained for a long time. I have no interest currently to learn how they work or to fix them. I also plan to remove direct proxy support in v2. So I will be closing the issue.

You're of course free to search for and use someone else's code that supports these proxies, or roll your own.