Big Company
Big Company

Reputation: 31

valueerror: you also need to provide a 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: '))

How can I pass it on phone_code_hash to the check client.sign_in(phone, input('Enter the code: '))

If you do not insert the cache, an error occurs valueerror: you also need to provide a phone_code_hash.

Upvotes: 3

Views: 2362

Answers (1)

mordi
mordi

Reputation: 86

The hash must be entered in the fifth entry

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)

I took the answer from here https://github.com/LonamiWebs/Telethon/blob/9445d2ba535ed7d214a7e6e68b85e7f3af1a690e/telethon/telegram_client.py#L141-L149

Upvotes: 2

Related Questions