【问题标题】:Flask 2.0 async - RuntimeError: Working outside of request contextFlask 2.0 async - RuntimeError:在请求上下文之外工作
【发布时间】:2021-09-03 22:18:36
【问题描述】:

在访问get_features POST api 时得到这个

RuntimeError: Working outside of request context
This typically means that you attempted to use functionality that needed
an active HTTP request.  Consult the documentation on testing for
information about how to avoid this problem.
@api_v1.route('/get_features', methods=['POST'])
async def get_features():
    results = []
    with app.app_context():
        inputs = request.json
        responses = await get_features_for_all(inputs)
        for response in responses:
            results.append(response)
        return jsonify({'result': results})

【问题讨论】:

    标签: flask python-asyncio flask-restful


    【解决方案1】:

    尝试不使用with app.app_context(): 行,因为您已经在上下文中(烧瓶路线)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多