奇怪的“is_xhr"将 Flask 应用程序部署到 Heroku 时出错
我有一个已部署到 Heroku 的 Flask 应用程序,其中一条路线如下
I have a flask app which I've deployed to Heroku, one of the routes is the following
def get_kws():
seed_kw = request.json['firstParam']
audience_max = request.json['secondParam']
interest_mining_service = InterestMiningService(seed_kw, audience_max)
query_result = interest_mining_service.query_keyword().tolist()
if seed_kw in query_result:
print ("yes")
return jsonify(
{
'keyword_data' : interest_mining_service.find_kws().to_json(orient='records'),
'query_results': query_result
}
)
当我在本地测试此端点时,向该端点发送 POST 和 GET 请求时没有问题.但是,当我部署到 Heroku 时,出现以下错误:
When I test this endpoint locally, I have no issues when sending POST and GET requests to that endpoint. However, when I deploy to Heroku, I get the following error:
File "/app/server/controller.py", line 24, in get_kws
2020-02-08T22:31:05.893850+00:00 app[web.1]: 'query_results': query_result
2020-02-08T22:31:05.893850+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/json.py", line 298, in jsonify
2020-02-08T22:31:05.893851+00:00 app[web.1]: if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
2020-02-08T22:31:05.893851+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/werkzeug/local.py", line 347, in __getattr__
2020-02-08T22:31:05.893852+00:00 app[web.1]: return getattr(self._get_current_object(), name)
2020-02-08T22:31:05.893858+00:00 app[web.1]: AttributeError: 'Request' object has no attribute 'is_xhr'
我以前从未见过这个错误 Request object has no attribute 'is_xhr'
并且它似乎只在我部署到 Heroku 时发生.关于我应该研究什么的任何指导?
I've never seen this error Request object has no attribute 'is_xhr'
before and it only seems to be happening when I deploy to Heroku. Any guidance on what I should look into?
json 键 keyword_data
似乎也没有问题 - 问题似乎仅限于 query_results
这是一个列表.
There also doesn't seem to be an issue with the json key keyword_data
- the issue seems limited to query_results
which is a list.
Werkzeug
库(依赖于 Flask
)最近收到了重大更新 (0.16.1 --> 1.0.0) 并且看起来 Flask
(
The Werkzeug
library (dependency from Flask
) recently received a major update (0.16.1 --> 1.0.0) and it looks like Flask
(<=0.12.4) does not restrict the version of Werkzeug that is fetched.
您有两个选择:
坚持使用当前版本的 Flask 并通过指定
werkzeug 或
werkzeug= 限制在应用程序的 setup.py 或 requirements.txt 中显式获取的 Werkzeug 版本=0.16.1
升级到最新版本的 Flask (>=1.0.0),它在最新的 Werkzeug 上运行良好
Upgrade to a recent version of Flask (>=1.0.0), which is running fine with latest Werkzeug