python - Telethon Cannot sign into accounts with two step verfication
问题描述
I'm trying to log into telegram using telethon with a number with two-step verification. I use this code,
client = TelegramClient(f'sessions/1', API_ID, API_HASH)
client.connect()
phone = input('phone ; ')
y = client.send_code_request(phone)
x = client.sign_in(phone=phone, password=input('password : '), code=input('code :'))
But It still says that the account is two-step protected. Is there any easier way to do this without this method or... how can I properly use this method?
I want to log into the account fully from the code without typing anything in the terminal (Here I used inputs just for testing. I will connect a GUI later where users can enter the details) so I don't think client.start()
will work. and I'm a little confused when it comes to passing the parameters to client.start()
method.
Any help would be really appreciated. Thank you.
解决方案
您还需要传递phone_code_hash
从client.send_code_request(phone)
.
您可以尝试(参见带有 phone_code_hash 和send_code_request的sign_in函数调用):
y = client.send_code_request(phone)
client.sign_in(phone=phone, password=input('password : '), code=input('code :'), phone_code_hash=y.phone_code_hash)
推荐阅读
- java - 密码字段作为招摇 ui 上的输入文本
- c++ - 来自弱指针的回调包装器
- android - 如何使用颤振工作管理器进行颤振和 FCM
- routes - 两个航点之间的距离 HERE MAPS ROUTING API
- django - Django m2m_changed 信号,post_add 在 post_remove 之后自动调用
- pandas - 熊猫,将简单函数应用于 NaN 返回值而不是 NaN?
- javascript - 在href中写一些东西而不影响html文件的路径
- python - 在Python中按具有相同名称的列平均行
- javascript - 如何在电视应用程序的 react-native 中获取所选元素
- sql - Sql 完全外连接查询在 SQLAlchemy 中不起作用