奇怪的"is_xhr"将Flask应用程序部署到Heroku时出错 [英] Weird "is_xhr" error when deploying Flask app to Heroku
问题描述
我有一个烧瓶应用程序,已将其部署到Heroku,其中一条路线如下
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
(< = 0.12.4)并不限制所获取的Werkzeug的版本.
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.
您有2个选择:
-
用当前的Flask版本粘贴,并通过指定
werkzeug<1.0
或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
这篇关于奇怪的"is_xhr"将Flask应用程序部署到Heroku时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!