mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
parent
6e4c437340
commit
3e611cdd42
|
@ -160,7 +160,7 @@ class TelegramClient:
|
|||
|
||||
# region Telegram requests functions
|
||||
|
||||
def invoke(self, request, timeout=timedelta(seconds=5), throw_invalid_dc=False, tries=3, expect_result=True):
|
||||
def invoke(self, request, timeout=timedelta(seconds=5), throw_invalid_dc=False):
|
||||
"""Invokes a MTProtoRequest (sends and receives it) and returns its result.
|
||||
An optional timeout can be given to cancel the operation after the time delta.
|
||||
Timeout can be set to None for no timeout.
|
||||
|
@ -174,14 +174,7 @@ class TelegramClient:
|
|||
self.sender.send(request)
|
||||
self.sender.receive(request, timeout)
|
||||
|
||||
if request.result is None and expect_result:
|
||||
if tries == 0:
|
||||
raise ValueError('The result of the invoked request is always None')
|
||||
else:
|
||||
return self.invoke(request, timeout, throw_invalid_dc, tries - 1, expect_result)
|
||||
else:
|
||||
# Either the result is not None or we don't expect it to be different
|
||||
return request.result
|
||||
return request.result
|
||||
|
||||
except InvalidDCError as error:
|
||||
if throw_invalid_dc:
|
||||
|
@ -267,7 +260,7 @@ class TelegramClient:
|
|||
def log_out(self):
|
||||
"""Logs out and deletes the current session. Returns True if everything went OK"""
|
||||
try:
|
||||
self.invoke(LogOutRequest(), expect_result=False)
|
||||
self.invoke(LogOutRequest())
|
||||
if not self.session.delete():
|
||||
return False
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user