[英]Python Flask app (Telegram Bot) on Heroku not running
I am using Heroku to host a Telegram Bot script in python using Flask.我正在使用 Heroku 使用 Flask 在 python 中托管 Telegram Bot 脚本。 I've gone through the process of setting everything up, including the git, the virtual enviroment (
#py -m venv env
+ #env\Scripts\activate
and the script... It gives no errors but it doesn't run... I've installed Flask and Gunicorn in the env:我已经完成了所有设置的过程,包括 git、虚拟环境(
#py -m venv env
+ #env\Scripts\activate
和脚本......它没有给出任何错误,但它没有运行。 .. 我已经在环境中安装了 Flask 和 Gunicorn:
#pip install flask
#set FLASK_APP=app.py
#pip install gunicorn
FILES IN THE PROJECT:项目中的文件:
.gitignore -> .gitignore ->
env
Procfile ->过程文件 ->
web: gunicorn deploy:app
deploy.py ->部署.py ->
import os
from flask import Flask, request
import telebot
TOKEN = 'My token here'
bot = telebot.TeleBot(TOKEN)
app = Flask(__name__)
@bot.message_handler(commands=['start'])
def start(message):
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
bot.reply_to(message, message.text)
@app.route('/' + TOKEN, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
@app.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url='My Url here' + TOKEN)
return "!", 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
I Think problem associated with procfile.first check whether you add gunicorn
to requirements.txt
file or not.According to me instead of using Gunicorn just deploy with Common Procfile.我认为与 procfile 相关的问题。首先检查您是否将
gunicorn
添加到requirements.txt
文件中。根据我的说法,而不是使用 Gunicorn,只需使用 Common Procfile 部署即可。
Try with this procfile Procfile
-- web: python deploy.py
试试这个 procfile
Procfile
-- web: python deploy.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.