LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.09k stars 1.41k forks source link

When i run my app with StringSession and tryin to sign_in it raise phone code expired #4509

Open shared-object opened 4 days ago

shared-object commented 4 days ago

Code that causes the issue

try:
            user = await client.sign_in(
                phone, str(message.text), phone_code_hash=phone_code_hash
            )
except PhoneCodeExpiredError:
            return await message.reply(
                "Срок кода истек. Попробуйте еще раз",
                reply_markup=keyboards.send_code_again(),
            )

this how i tryin to sign in

async def create_client_from_account(account: Account):
    return TelegramClient(
        StringSession(account.session_string),
        api_id=int(account.api_id),
        api_hash=account.api_hash,
        device_model=account.device_model,
        system_version=account.system_version,
        app_version=account.app_version,
        proxy=default_to_telethon_proxy(account.proxy),  # type: ignore
    )

this is how i create da client

Expected behavior

I was expecting that it will sign in correctly

Actual behavior

Instead of this it raised a PhoneCodeExpired error

Traceback


tfcb_tg        | Traceback (most recent call last):
tfcb_tg        |   File "/usr/src/project/source/handlers/accounts.py", line 264, in process_code
tfcb_tg        |     user = await client.sign_in(
tfcb_tg        |            ^^^^^^^^^^^^^^^^^^^^^
tfcb_tg        |   File "/usr/local/lib/python3.12/site-packages/telethon/client/auth.py", line 357, in sign_in
tfcb_tg        |     result = await self(request)
tfcb_tg        |              ^^^^^^^^^^^^^^^^^^^
tfcb_tg        |   File "/usr/local/lib/python3.12/site-packages/telethon/client/users.py", line 30, in __call__
tfcb_tg        |     return await self._call(self._sender, request, ordered=ordered)
tfcb_tg        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tfcb_tg        |   File "/usr/local/lib/python3.12/site-packages/telethon/client/users.py", line 87, in _call
tfcb_tg        |     result = await future
tfcb_tg        |              ^^^^^^^^^^^^
tfcb_tg        | telethon.errors.rpcerrorlist.PhoneCodeExpiredError: The confirmation code has expired (caused by SignInRequest)```

### Telethon version

1.37.0

### Python version

python --version

### Operating system (including distribution name and version)

Artic Linux

### Other details

_No response_

### Checklist

- [X] The error is in the library's code, and not in my own.
- [X] I have searched for this issue before posting it and there isn't an open duplicate.
- [X] I ran `pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip` and triggered the bug in the latest version.
shared-object commented 4 days ago

Code that causes the issue

try:
            user = await client.sign_in(
                phone, str(message.text), phone_code_hash=phone_code_hash
            )
except PhoneCodeExpiredError:
            return await message.reply(
                "Срок кода истек. Попробуйте еще раз",
                reply_markup=keyboards.send_code_again(),
            )

this how i tryin to sign in

async def create_client_from_account(account: Account):
    return TelegramClient(
        StringSession(account.session_string),
        api_id=int(account.api_id),
        api_hash=account.api_hash,
        device_model=account.device_model,
        system_version=account.system_version,
        app_version=account.app_version,
        proxy=default_to_telethon_proxy(account.proxy),  # type: ignore
    )

this is how i create da client

Expected behavior

I was expecting that it will sign in correctly

Actual behavior

Instead of this it raised a PhoneCodeExpired error

Traceback

tfcb_tg        | Traceback (most recent call last):
tfcb_tg        |   File "/usr/src/project/source/handlers/accounts.py", line 264, in process_code
tfcb_tg        |     user = await client.sign_in(
tfcb_tg        |            ^^^^^^^^^^^^^^^^^^^^^
tfcb_tg        |   File "/usr/local/lib/python3.12/site-packages/telethon/client/auth.py", line 357, in sign_in
tfcb_tg        |     result = await self(request)
tfcb_tg        |              ^^^^^^^^^^^^^^^^^^^
tfcb_tg        |   File "/usr/local/lib/python3.12/site-packages/telethon/client/users.py", line 30, in __call__
tfcb_tg        |     return await self._call(self._sender, request, ordered=ordered)
tfcb_tg        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tfcb_tg        |   File "/usr/local/lib/python3.12/site-packages/telethon/client/users.py", line 87, in _call
tfcb_tg        |     result = await future
tfcb_tg        |              ^^^^^^^^^^^^
tfcb_tg        | telethon.errors.rpcerrorlist.PhoneCodeExpiredError: The confirmation code has expired (caused by SignInRequest)```

### Telethon version

1.37.0

### Python version

python --version

### Operating system (including distribution name and version)

Artic Linux

### Other details

_No response_

### Checklist

- [X] The error is in the library's code, and not in my own.
- [X] I have searched for this issue before posting it and there isn't an open duplicate.
- [X] I ran `pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip` and triggered the bug in the latest version.

python version - Python 3.12.7

shared-object commented 4 days ago

and artix linux unstead of artic