开发者社区> 问答> 正文

flask 读取请求body报错

from flask import Flask,request


app=Flask(__name__)


@app.route("/abc",methods=["post"])
def index():
    print(request.body)
    return "cd",200

if __name__=="__main__":
    app.run()

报错

Traceback (most recent call last):
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 2070, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "b.py", line 9, in index
    print(request.body)
AttributeError: 'Request' object has no attribute 'body'

展开
收起
水果黄瓜 2021-10-23 21:05:53 1216 0
1 条回答
写回答
取消 提交回答
  • 在flask中,读取请求内容,不是使用request.body,而是使用request.data

    2021-10-25 21:54:00
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载