Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

Telegram does not send authorization code if the request was sent from telethon code hosted on Heroku

I have a problem when using the Telethon Python client for Telegram for logging in.

The script below works perfectly fine when I run it on my own laptop: it prints a SentCode object, Telegram sends me a confirmation code, and I use it to log in.

When I run exactly the same script on Heroku, it still prints the same SentCode object, however, I don't receive any confirmation code from Telegram and cannot continue logging in.

from telethon import sync  # noqa
from telethon import TelegramClient
from telethon.sessions import StringSession
client = TelegramClient(session=StringSession(), api_hash=API_HASH, api_id=API_ID)
client.connect()
result = client.send_code_request(phone=PHONE)
print(result)
# prints SentCode(type=SentCodeTypeApp(length=5), phone_code_hash=..., next_type=CodeTypeSms(), timeout=None)
... the code for logging in and saving the session...

It seems that Telegram doesn't acknowledge authorization from Heroku for security reasons - maybe, Heroku is often used to host malicious bots, and Telegram fights them this way. However, neither Telethon nor MTProto documentation reflects this restriction. So I wonder, how is it even possible to use MTProto clients like Telethon from a cloud platform? And if it is possible, what should I do to get around this restriction?

question from:https://stackoverflow.com/questions/65869010/telegram-does-not-send-authorization-code-if-the-request-was-sent-from-telethon

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...