diff --git a/pyrogram/client.py b/pyrogram/client.py index 3009f0f6..9a31b3d7 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -95,6 +95,10 @@ class Client(Methods): Pass True to connect to Telegram using IPv6. Defaults to False (IPv4). + alt_port (``bool``, *optional*): + Pass True to connect to Telegram using alternative port (5222). + Defaults to False (443). + proxy (``dict``, *optional*): The Proxy settings as dict. E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*. @@ -205,6 +209,7 @@ class Client(Methods): system_version: str = SYSTEM_VERSION, lang_code: str = LANG_CODE, ipv6: bool = False, + alt_port: bool = False, proxy: dict = None, test_mode: bool = False, bot_token: str = None, @@ -234,6 +239,7 @@ class Client(Methods): self.system_version = system_version self.lang_code = lang_code self.ipv6 = ipv6 + self.alt_port = alt_port self.proxy = proxy self.test_mode = test_mode self.bot_token = bot_token diff --git a/pyrogram/connection/connection.py b/pyrogram/connection/connection.py index 618c92a5..2a0f0955 100644 --- a/pyrogram/connection/connection.py +++ b/pyrogram/connection/connection.py @@ -37,13 +37,14 @@ class Connection: 4: TCPIntermediateO } - def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False, mode: int = 3): + def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, alt_port: bool, proxy: dict, media: bool = False, mode: int = 3): self.dc_id = dc_id self.test_mode = test_mode self.ipv6 = ipv6 + self.alt_port = alt_port self.proxy = proxy self.media = media - self.address = DataCenter(dc_id, test_mode, ipv6, media) + self.address = DataCenter(dc_id, test_mode, ipv6, alt_port, media) self.mode = self.MODES.get(mode, TCPAbridged) self.protocol = None # type: TCP diff --git a/pyrogram/session/auth.py b/pyrogram/session/auth.py index 7df4fede..65581f03 100644 --- a/pyrogram/session/auth.py +++ b/pyrogram/session/auth.py @@ -41,6 +41,7 @@ class Auth: self.dc_id = dc_id self.test_mode = test_mode self.ipv6 = client.ipv6 + self.alt_port = client.alt_port self.proxy = client.proxy self.connection = None @@ -76,7 +77,7 @@ class Auth: # The server may close the connection at any time, causing the auth key creation to fail. # If that happens, just try again up to MAX_RETRIES times. while True: - self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy) + self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.alt_port, self.proxy) try: log.info(f"Start creating a new auth key on DC{self.dc_id}") diff --git a/pyrogram/session/internals/data_center.py b/pyrogram/session/internals/data_center.py index d3146263..4435da5b 100644 --- a/pyrogram/session/internals/data_center.py +++ b/pyrogram/session/internals/data_center.py @@ -60,7 +60,7 @@ class DataCenter: 4: "2001:067c:04e8:f004:0000:0000:0000:000b" } - def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> Tuple[str, int]: + def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, alt_port: bool, media: bool) -> Tuple[str, int]: if test_mode: if ipv6: ip = cls.TEST_IPV6[dc_id] @@ -79,5 +79,4 @@ class DataCenter: ip = cls.PROD_MEDIA.get(dc_id, cls.PROD[dc_id]) else: ip = cls.PROD[dc_id] - - return ip, 443 + return ip, 5222 if alt_port else 443 diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 6fea9337..fbcec870 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -97,6 +97,7 @@ class Session: self.dc_id, self.test_mode, self.client.ipv6, + self.client.alt_port, self.client.proxy, self.is_media )