推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
daiqiangbudainiu
V2EX  ›  Python

flask 的 request 必须手动读完才能 return 吗?

  •  
  •   daiqiangbudainiu · Jan 21, 2019 · 1570 views
    This topic created in 2811 days ago, the information mentioned may be changed or developed.
    @DS_profile.route('/REG-MITRA.html', methods=['POST'])
    def regmitra_mock():
        data = request.data
        return jsonify(get_resp_from_file('REG-MITRA.json'))
    

    代码如上,我这个东西只是想 Mock 一下第三方的接口,所以我是无脑返回 json 文件中的内容的,我必须加上

    data = request.data
    

    然后系统在调用这个接口的时候,不会报错

    不然会抛出 Connection Reset 异常

    通过抓包分析发现,出现 Connection Reset 的时候,request body 还没有发送完,client 就收到了 flask 返回的 response

    我感觉 flask 框架应该会自动帮我做这个事情啊

    不太理解为什么会出现这种问题

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2445 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:58 · PVG 21:58 · LAX 06:58 · JFK 09:58
    ♥ Do have faith in what you're doing.