首页 > 解决方案 > valueerror: 你还需要提供一个phone_code_hash

问题描述

from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty

api_id = XXXXXXX
api_hash = 'XXXXXXXXXXXXXXXXXXXXXXXX'
phone = '+XXXXXXXXXXX'

client = TelegramClient(phone, api_id, api_hash)

client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    phone_code_hash = client.send_code_request(phone).phone_code_hash


client = TelegramClient(phone, api_id, api_hash)

client.connect()
client.sign_in(phone, input('Enter the code: '))

如何将其传递phone_code_hash给检查 client.sign_in(phone, input('Enter the code: '))

如果不插入缓存,就会出现错误valueerror: you also need to provide a phone_code_hash.

标签: pythontelegramtelegram-bottelethon

解决方案


必须在第五个条目中输入哈希

client = TelegramClient(phone, api_id, api_hash)
client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    phone_code_hash = client.send_code_request(phone).phone_code_hash

client = TelegramClient(phone, api_id, api_hash)
client.connect()
client.sign_in(phone, input('Enter the code: '), phone_code_hash=phone_code_hash)

我从这里得到了答案https://github.com/LonamiWebs/Telethon/blob/9445d2ba535ed7d214a7e6e68b85e7f3af1a690e/telethon/telegram_client.py#L141-L149


推荐阅读