From 9f3f4099d5b9fa6ce1f278299752fea54f3a4cb3 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 5 May 2018 19:42:38 +0200 Subject: [PATCH] Handle timeouts when getting answers from inline bots --- pyrogram/client/client.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index c1d02f55..0bbe41a0 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -45,7 +45,7 @@ from pyrogram.api.errors import ( PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing, ChatAdminRequired, FirstnameInvalid, PhoneNumberBanned, - VolumeLocNotFound, UserMigrate, FileIdInvalid) + VolumeLocNotFound, UserMigrate, FileIdInvalid, UnknownError) from pyrogram.crypto import AES from pyrogram.session import Auth, Session from pyrogram.session.internals import MsgId @@ -3586,18 +3586,27 @@ class Client: Raises: :class:`Error ` """ - return self.send( - functions.messages.GetInlineBotResults( - bot=self.resolve_peer(bot), - peer=types.InputPeerSelf(), - query=query, - offset=offset, - geo_point=types.InputGeoPoint( - lat=location[0], - long=location[1] - ) if location else None + # TODO: Split location parameter into lat and long + + try: + return self.send( + functions.messages.GetInlineBotResults( + bot=self.resolve_peer(bot), + peer=types.InputPeerSelf(), + query=query, + offset=offset, + geo_point=types.InputGeoPoint( + lat=location[0], + long=location[1] + ) if location else None + ) ) - ) + except UnknownError as e: + # TODO: Add this -503 Timeout error into the Error DB + if e.x.error_code == -503 and e.x.error_message == "Timeout": + raise TimeoutError("The inline bot didn't answer in time") from None + else: + raise e def send_inline_bot_result(self, chat_id: int or str, @@ -3807,5 +3816,3 @@ class Client: r = self.send(functions.messages.GetFullChat(peer.chat_id)) return utils.parse_chat_full(self, r) - -