python - pyrogram bot can not login and raise PhoneCodeExpired exception - Stack Overflow

I wrote a bot so that I can create a session for a user by taking their phone number. Everything works

I wrote a bot so that I can create a session for a user by taking their phone number. Everything works fine until the line await cli.sign_in(f'{phone_number}', f'{code.phone_code_hash}', ramz) is called, and then the program gives the following error:

pyrogram.errors.exceptions.bad_request_400.PhoneCodeExpired: Telegram says: [400 PHONE_CODE_EXPIRED] - The confirmation code has expired (caused by "auth.SignIn")"


my code :

@app.on_message(contacts)
async def register_mobile(client, message):
    user_number = message.contact.phone_number
    user_id = message.from_user.id
    # create session for user with phone number
    cli = Client("4984920", api_id_975, api_hash_975)
    await cli.connect()
    code = await cli.send_code(user_number)
    print('we are here')
    temp[user_id] = [cli,user_number,code]
    print(temp)
    await message.reply(
            f"send telegram code to bot"
    )

@app.on_message()
async def handler4(c,m):
    print('here we are')
    if (data:=temp[m.from_user.id]):
        cli,phone_number,code = data
        print(code)
        ramz = str(m.text)
        print(ramz,len(ramz),type(ramz))
        await cli.sign_in(f'{phone_number}',f'{code.phone_code_hash}',ramz)
        print('done')
        string_session = await cli.export_session_string()
        print(f"Session String:\n{string_session}")

"What is the solution? Is the issue related to the current event loop being used?"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745673552a4639547.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信