微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果请求是从 Heroku 上托管的 Telethon 代码发送的,则 Telegram 不会发送授权代码

如何解决如果请求是从 Heroku 上托管的 Telethon 代码发送的,则 Telegram 不会发送授权代码

我在使用 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 客户端?如果可能的话,我应该怎么做才能绕过这个限制?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。