Heroku 成功部署,但我仍然没有运行任何 web 进程 [英] Heroku successfully deployed but I still keep getting no web process running
问题描述
我正在尝试将电报机器人推送到 Heroku.这些是我文件夹中的文件.
I'm trying to push a telegram bot into Heroku. These are files within my folder.
/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 文本编辑器.
My procfile does NOT have any .txt extension. Inside the procfile is worker: python new_bot.py
I am using atom text editor.
在我的需求 .txt 文件夹中,这些是以下需求
In my requirements .txt folder, these are the following requirements
requests
telegram
tornado>=5.1
new_bot.py 脚本在这里
The new_bot.py script is here
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
,成功部署它,显示了这一点:
So it managed to build successfully, and I ran and did heroku ps:scale worker=1
in my heroku CLI, managed to deploy it successfully which showed this:
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 上,我看到了这个
On my Heroku UI, I am seeing this
worker
python new_bot.py
ON
但是,我仍然收到此错误 at=error code=H14 desc="No web processes running";方法=GET
.我在Stackoverflow中看到很多地方不得不使用heroku ps:scale web=1
,这与我之前使用的命令heroku ps:scale worker=1
不同代码>.我可以检查一下我在这里做错了什么以及如何补救吗?任何帮助将不胜感激.
However, I still keep getting this error at=error code=H14 desc="No web processes running" method=GET
. I have seen many places in Stackoverflow that I have to use heroku ps:scale web=1
, which is different from the command I used earlier which was heroku ps:scale worker=1
. Can I just check what am I doing wrong here and how do I remedy it? Any help will be appreciated.
大家好,我实际上已经找到了问题所在.这与
Hi guys I've actually found the problem already. It has to do with
updater.start_webhook(listen="0.0.0.0",
port=int(PORT),
url_path=TOKEN,
webhook_url='https://abc.herokuapp.com/' + TOKEN)
无论如何感谢您的帮助!
Thanks for helping anyway!
推荐答案
对于 heroku 中的 Web 进程,您需要在 Proc 文件中添加如下内容:
For a web process in heroku you need to add something like this to your Proc file:
以下是 Rails 等效项,您需要特定于您的应用程序.
Below is a rails equivalent, you need specific to your app.
web: bundle exec rails server -p $PORT
然后运行:
heroku ps:scale web=1
这篇关于Heroku 成功部署,但我仍然没有运行任何 web 进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!