我制作了一个简单的烧瓶应用程序,它从URL中的参数中收集数据,并将它们放入python模块中,该模块以Json格式发送输出,在本地机器上运行良好,但在部署到Heroku时会出现错误。错误消息只表示超时错误。下面是用于部署的应用程序的heroku链接- https://shodhapi.herokuapp.com/这里的代码
from nsepy import get_history
from datetime import date
import pandas as pd
from flask import Flask
from flask_caching import Cache
from flask import request
config = {
"CACHE_TYPE": "SimpleCache", # Flask-Caching related configs
"CACHE_DEFAULT_TIMEOUT": 300,
}
app = Flask(__name__)
# tell Flask to use the above defined config
app.config.from_mapping(config)
cache = Cache(app)
@app.route("/api")
@cache.cached(timeout=600)
def index():
ticker = request.args.get( 'ticker', None)
sy = int(request.args.get('sy', None))
sm = int(request.args.get('sm', None))
sd = int(request.args.get('sd', None))
ey = int(request.args.get('ey', None))
em = int(request.args.get('em', None))
ed = int(request.args.get('ed', None))
# 2022,1,31
results = get_history(symbol=ticker,start=date(sy,sm,sd),end=date(ey,em,ed))
results.reset_index(inplace=True)
results.set_index('Deliverable Volume', inplace=True)
results['Date'] = pd.to_datetime(results['Date'])
# convert dataframe to json
result_json = results.to_json(orient="records")
return result_json
if __name__ == "__main__":
app.run(debug=True)发布于 2022-05-24 17:20:37
我不是一个日常的烧瓶用户,但已经部署了一些Nodejs服务器到heroku。在Nodejs中,尽管它使用默认端口3000,但您必须首先检查heroku环境是否提供了一个名为PORT的环境变量。然后,您必须让服务器在该端口侦听。(如果没有提供这样的变量,那么您可以在默认的Nodejs端口,即3000上侦听)。
app.listen(process.env.PORT || 3000);在烧瓶里,你应该做一些类似的事情
import os
app.run(debug=True, port=int(os.environ.get('PORT', 5500)))假设5500是烧瓶的默认端口。
https://stackoverflow.com/questions/72366794
复制相似问题