diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 1848ba35..a16f27ab 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -91,10 +91,8 @@ class TCP: ) sock.settimeout(TCP.TIMEOUT) - await self.loop.sock_connect( - sock=sock, - address=destination - ) + # fix: Use run_in_executor for socks.socksocket + await self.loop.run_in_executor(None, sock.connect, destination) sock.setblocking(False) @@ -123,7 +121,7 @@ class TCP: async def connect(self, address: Tuple[str, int]) -> None: try: await asyncio.wait_for(self._connect(address), TCP.TIMEOUT) - except asyncio.TimeoutError: # Re-raise as TimeoutError. asyncio.TimeoutError is deprecated in 3.11 + except asyncio.TimeoutError: raise TimeoutError("Connection timed out") async def close(self) -> None: diff --git a/pyrogram/methods/payments/send_gift.py b/pyrogram/methods/payments/send_gift.py index b65d863b..40b709a3 100644 --- a/pyrogram/methods/payments/send_gift.py +++ b/pyrogram/methods/payments/send_gift.py @@ -77,7 +77,8 @@ class SendGift: """ peer = await self.resolve_peer(chat_id) - text, entities = (await utils.parse_text_entities(self, text, parse_mode, entities)).values() + result = await utils.parse_text_entities(self, text, parse_mode, entities) + text, entities = result["message"], result["entities"] invoice = raw.types.InputInvoiceStarGift( peer=peer, diff --git a/pyrogram/utils.py b/pyrogram/utils.py index fc0e9abd..31b8f1b0 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -436,13 +436,15 @@ async def parse_text_entities( entities: List["types.MessageEntity"] ) -> Dict[str, Union[str, List[raw.base.MessageEntity]]]: if entities: - # Inject the client instance because parsing user mentions requires it + for entity in entities: entity._client = client - text, entities = text, [await entity.write() for entity in entities] or None + text, entities = text, [await entity.write() for entity in entities] or [] else: - text, entities = (await client.parser.parse(text, parse_mode)).values() + parsed = await client.parser.parse(text, parse_mode) + + text, entities = parsed["message"], parsed.get("entities") or [] return { "message": text,