英文:
How to log in to telegram using pyrogram?
问题
请帮忙,在第一次运行时,我执行了send_code()
函数并保存了phone_code_hash
,在第二次运行时,我使用来自Telegram的代码和从send_code
函数中保存的散列代码执行了main()
,但在sign_in
时,我收到一个代码已过期的错误,尽管所有数据都是正确的。
英文:
Please help, on the first run, I executed the send_code() function and saved the phone_code_hash, on the second run, I executed main() with the code received from the telegram and the hash code saved from the send_code function, but when sign_in I get an error that the code has expired, although all data is correct.
client = Client(
'sessin',
api_id=app_id,
api_hash=app_hash,
)
async def send_code(phone_number):
await client.connect()
result = await client.send_code(phone_number)
phone_code_hash = result.phone_code_hash
async def main(phone_number, phone_code, phone_hash_code):
await client.connect()
result = await client.sign_in(phone_number=phone_number, phone_code=phone_code, phone_code_hash=phone_hash_code)
I tried to find information but didn't find it.
答案1
得分: 0
以下是使用Pyrogram登录的示例代码:
client = Client("sessions", api_id, api_hash)
client.connect()
sent_code = client.send_code(phone)
code = input("Enter the code : ")
signed_in = client.sign_in(phone, sent_code.phone_code_hash, code)
client.disconnect()
英文:
Here is example to login with pyrogram.
client = Client("sessions", api_id, api_hash)
client.connect()
sent_code = client.send_code(phone)
code = input("Enter the code : ")
signed_in = client.sign_in(phone, sent_code.phone_code_hash, code)
client.disconnect()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论