【问题标题】:Heroku successfully deployed but I still keep getting no web process runningHeroku 成功部署,但我仍然没有运行任何 Web 进程
【发布时间】:2021-09-24 08:51:11
【问题描述】:

我正在尝试将电报机器人推送到 Heroku。这些是我文件夹中的文件。

/new_bot
---/requirements.txt
---/Procfile   #worker: python new_bot.py 
---/init.py    #empty
---/new_bot.py
---/.env

我的 procfile 没有任何 .txt 扩展名。 procfile里面是worker: python new_bot.py我用的是atom文本编辑器。

在我的需求 .txt 文件夹中,这些是以下需求

requests
telegram
tornado>=5.1

new_bot.py 脚本在这里

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler, CallbackContext
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
import requests

PORT = int(os.environ.get('PORT', 443))

TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")

def hello(update, context):
    update.message.reply_text('Hello! \U0001F600')

def main():  
    updater = Updater(TOKEN, use_context=True)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("hello", hello))
    updater.start_webhook(listen="0.0.0.0",
                          port=int(PORT),
                          url_path=TOKEN,
                          webhook_url='https://abc.herokuapp.com/' + TOKEN)

    updater.start_polling()

    updater.idle()
if __name__ == '__main__':
    main()

所以它成功构建,我在 heroku CLI 中运行并执行了heroku ps:scale worker=1,成功部署它,这表明:

2021-07-15T11:56:11.022397+00:00 heroku[worker.1]: State changed from crashed to starting
2021-07-15T11:56:15.944190+00:00 heroku[worker.1]: Starting process with command `python new_bot.py`
2021-07-15T11:56:17.093075+00:00 heroku[worker.1]: State changed from starting to up
2021-07-15T11:56:21.000000+00:00 app[api]: Build succeeded
2021-07-15T11:56:22.155897+00:00 app[worker.1]: 2.26.0

在我的 Heroku UI 上,我看到了这个

worker
python new_bot.py
ON

但是,我仍然不断收到此错误at=error code=H14 desc="No web processes running" method=GET。我在 Stackoverflow 中看到很多地方都必须使用 heroku ps:scale web=1,这与我之前使用的命令 heroku ps:scale worker=1 不同。我可以检查一下我在这里做错了什么,我该如何补救?任何帮助将不胜感激。

编辑:大家好,我实际上已经发现了问题。这与

有关
updater.start_webhook(listen="0.0.0.0",
                          port=int(PORT),
                          url_path=TOKEN,
                          webhook_url='https://abc.herokuapp.com/' + TOKEN)

感谢您的帮助!

【问题讨论】:

  • 鉴于您的 Procfile 上的定义,您的测功机的名称是 worker,所以这样做 heroku ps:scale worker=1 应该缩放这个测功机,换句话说应该是向上的。检查您的测功机是否与heroku ps一致,此命令将显示您所有的测功机。
  • 一个问题,这个错误,I still keep getting this error at=error code=H14 desc="No web processes running" method=GET,当你尝试访问web 应用程序时,你得到了这个错误,对吧?我的意思是,通过浏览器?如果是这种情况,您不应该这样做,因为您尚未部署 web dyno。正如您所部署的那样,电报机器人在后台,并将响应您通过电报发送的任何消息。
  • 嗨@Gealber,我实际上已经尝试过heroku ps,它显示了这个worker.1: starting 2021/07/17 10:11:09 +0800 (~ 8s ago),但是当我尝试接收消息时,它没有返回任何内容。

标签: python heroku telegram


【解决方案1】:

对于 heroku 中的 Web 进程,您需要在 Proc 文件中添加类似这样的内容:

下面是一个等效的 Rails,您需要特定于您的应用程序。

web: bundle exec rails server -p $PORT

然后运行:

heroku ps:scale web=1

【讨论】:

    猜你喜欢
    • 2016-02-27
    • 2012-04-25
    • 2012-07-09
    • 2022-08-07
    • 1970-01-01
    • 2017-01-08
    • 2021-09-30
    • 2021-01-18
    • 1970-01-01
    相关资源
    最近更新 更多