From af1853872247d48456833990130a66cde982cbcf Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 6 Apr 2023 14:36:24 +0200 Subject: [PATCH] Handle PhoneCodeExpiredError during sign_in Closes #3185. --- telethon/client/auth.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/telethon/client/auth.py b/telethon/client/auth.py index 520efc56..bdc8cf6d 100644 --- a/telethon/client/auth.py +++ b/telethon/client/auth.py @@ -333,9 +333,12 @@ class AuthMethods: # May raise PhoneCodeEmptyError, PhoneCodeExpiredError, # PhoneCodeHashEmptyError or PhoneCodeInvalidError. - request = functions.auth.SignInRequest( - phone, phone_code_hash, str(code) - ) + try: + request = functions.auth.SignInRequest( + phone, phone_code_hash, str(code) + ) + except errors.PhoneCodeExpiredError: + self._phone_code_hash.pop(phone, None) elif password: pwd = await self(functions.account.GetPasswordRequest()) request = functions.auth.CheckPasswordRequest(