From 5b1135734bdcc246faa01954cf75b6416c2aeee0 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 6 Apr 2023 18:52:45 +0200 Subject: [PATCH] Properly handle PhoneCodeExpiredError in sign_in Should actually fix #3185 now. --- telethon/client/auth.py | 16 +++++++++------- telethon/version.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/telethon/client/auth.py b/telethon/client/auth.py index bdc8cf6d..be1f591a 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -333,12 +333,9 @@ class AuthMethods: # May raise PhoneCodeEmptyError, PhoneCodeExpiredError, # PhoneCodeHashEmptyError or PhoneCodeInvalidError. - try: - request = functions.auth.SignInRequest( - phone, phone_code_hash, str(code) - ) - except errors.PhoneCodeExpiredError: - self._phone_code_hash.pop(phone, None) + request = functions.auth.SignInRequest( + phone, phone_code_hash, str(code) + ) elif password: pwd = await self(functions.account.GetPasswordRequest()) request = functions.auth.CheckPasswordRequest( @@ -355,7 +352,12 @@ class AuthMethods: 'and a password only if an RPCError was raised before.' ) - result = await self(request) + try: + result = await self(request) + except errors.PhoneCodeExpiredError: + self._phone_code_hash.pop(phone, None) + raise + if isinstance(result, types.auth.AuthorizationSignUpRequired): # Emulate pre-layer 104 behaviour self._tos = result.terms_of_service diff --git a/telethon/version.py b/telethon/version.py index 41a5c54c..074e1b20 100644 --- a/telethon/version.py +++ b/telethon/version.py @@ -1,3 +1,3 @@ # Versions should comply with PEP440. # This line is parsed in setup.py: -__version__ = '1.28.0' +__version__ = '1.28.1'