我正在尝试运行一个使用工作程序检索推文的服务器。我尝试运行heroku ps:scale worker=1
并成功了,但是Web界面什么都没得到。
我仍然遇到此错误:
at =错误代码= H14 desc =“没有Web进程正在运行” method = GET path =“ /” host = www.com.com request_id = fwd =“” dyno = connect = service =状态= 503字节=协议= https
这是我的代码:
from flask import Flask, jsonify
from flask_cors import CORS
from python_tweepy import Python_Tweepy
import json
app = Flask(__name__)
CORS(app)
@app.route("/")
def tweets():
#Return a dict with tweets. This is the worker
dataTweet = Python_Tweepy.createData()
#Transform into a json and return it to a web
return jsonify({'status': 'ok' ,'json_data':dataTweet})
if __name__=='__main__':
app.run(debug=True)
我希望在网站的/中有带有推文的JSON
这是我的Procfile
:
worker: python server.py
答案 0 :(得分:0)
Heroku通过PORT
环境变量告诉您要监听哪个端口。您可以通过在server.py
中执行以下操作来使用它:
import os
# Set port from the environment, falling back to port 5000 if it isn't set
port = os.getenv('PORT', default=5000)
# ...
if __name__=='__main__':
app.run(debug=True, port=port) # Listen on the specified port