admin管理员组文章数量:1435859
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?"
本文标签: pythonpyrogram bot can not login and raise PhoneCodeExpired exceptionStack Overflow
版权声明:本文标题:python - pyrogram bot can not login and raise PhoneCodeExpired exception - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745673552a2669713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论