Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shared-object opened this issue Nov 27, 2024 · 4 comments

Comments

@shared-object
Copy link

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
Copy link
Author

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
Copy link
Author

and artix linux unstead of artic

@DevJourney-web
Copy link

            user = await client.sign_in(
                phone, str(message.text), phone_code_hash=phone_code_hash

As far as I know, if you get an authorization code and enter it into your bot by text, Telegram immediately revokes it for security reasons.
InlineButtons helped me personally

@shared-object
Copy link
Author

            user = await client.sign_in(
                phone, str(message.text), phone_code_hash=phone_code_hash

As far as I know, if you get an authorization code and enter it into your bot by text, Telegram immediately revokes it for security reasons. InlineButtons helped me personally

Its only when you send code from that account which you logging in, with standart .sessions file works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants