0

我在使用Telethon Python 客户端进行 Telegram 登录时遇到问题。

下面的脚本在我自己的笔记本电脑上运行时运行良好:它打印一个 SentCode 对象,Telegram 向我发送一个确认码,然后我用它来登录。

当我在 Heroku 上运行完全相同的脚本时,它仍然会打印相同的 SentCode 对象,但是,我没有收到来自 Telegram 的任何确认码并且无法继续登录。

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...

出于安全原因,Telegram 似乎不承认 Heroku 的授权——也许,Heroku 经常被用来托管恶意机器人,而 Telegram 以这种方式对抗它们。但是,TelethonMTProto文档均未反映此限制。所以我想知道,怎么可能从云平台使用像 Telethon 这样的 MTProto 客户端?如果可能的话,我应该怎么做才能绕过这个限制?

4

0 回答 0