【问题标题】:Hosting a Telethon User BOT on google-app-engine在 google-app-engine 上托管 Telethon 用户 BOT
【发布时间】:2020-09-05 03:12:27
【问题描述】:

我正在尝试在运行 python3.7 的 Google App Engine 灵活环境上部署一个简单的用户机器人,但出现以下错误。谁能帮我提出解决这个问题的建议?

“文件”/env/lib/python3.7/site-packages/telethon/client/auth.py”,第 20 行,在电话中:typing.Callable[[], str] = lambda: input('请输入您的手机(或机器人令牌):'),EOFError: EOF when reading a line"

感谢您的宝贵时间

【问题讨论】:

  • 您的客户端似乎在提示输入,这在部署到 AppEngine 时不起作用。你能以其他方式提供电话号码或令牌吗?

标签: google-app-engine-python telethon


【解决方案1】:

Telethon(显然)要求您登录并在您的帐户上进行正常的用户会话,这本机要求您在被询问时输入您的号码并输入收到的代码,但由于 Google App 引擎不允许输入 @Sashidhar 提到, 根据你的 userbot 实现,你可以尝试使用 userbot.session 方法进行身份验证,它可以在本地生成并放置在 Google App Engine 中。

【讨论】:

    【解决方案2】:

    我尝试在应用程序引擎上使用 python 来调用 Telethon 函数,在部署应用程序时。我从浏览器收到内部服务器错误。

    我看到你在这条道路上取得了成功,你能帮我启动一下吗,比如如何配置 app.yaml、main.py、requirements.txt ,....或任何适当的图书馆安排来完成这项工作。

    非常感谢。

    以下是我的 main.py,它在浏览器上引发了服务器内部错误,如果注释了第一个与 Telethon 相关的行,则不会发生此问题:

    client = TelegramClient(phone, api_id, api_hash)

    main.py
    --------
    from flask import Flask, request
    import datetime
    import time
    import asyncio
    
    from telethon import  TelegramClient, events, sync
    
    app = Flask(__name__)
    
    api_id = xxxxxxxx
    api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxx'
    phone = '+xxxxxxxxxxxx'
    
    @app.route('/', methods=['GET'])
    def hello():
        reqaction = request.args.get('action', 'connect')
        client = TelegramClient(phone, api_id, api_hash) 
    
    if __name__ == '__main__':
        app.run(host='localhost', port=8080, debug=True)
    

    您能帮我启动一下吗,非常感谢

    【讨论】:

    • ps:我已经使用另一个通过 GAE 控制台(不是部署的应用程序)执行的 connect.py 成功登录 tg,因此会话文件被存储并可用于上述 main.py 但是我只是不能部署应用程序调用并使用 Telehon 功能,例如 TelegramClient(phone, api_id, api_hash)
    【解决方案3】:

    我现在可以使用会话字符串登录方法在 GAE 上托管我的用户 BOT。

    https://docs.telethon.dev/en/latest/concepts/sessions.html#string-sessions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 2021-02-25
      • 2019-03-02
      • 1970-01-01
      相关资源
      最近更新 更多