Flask Restful 解析 POST 数据
Flask Restful Parse POST data
我正在向 Flask Restful API
发送带有 cURL
的 POST 请求,因为:
curl -X POST -H 'Content-Type: text/csv' -d @trace.csv http://localhost:5000/upload
我无法从此请求中读取此数据,或者我不知道如何读取数据。下面是我对 API
:
的实现
class ForBetaAndUpload(Resource):
def post(self, kind='quotes'):
parser = reqparse.RequestParser()
parser.add_argument('file')
args = parser.parse_args()['file']
print(args) #Prints: Null
api.add_resource(ForBetaAndUpload, '/upload', endpoint='upload')
if __name__ == "__main__":
app.run(debug=True)
如何读取我用 cURL
发送的 csv 文件数据。非常感谢你的帮助。
默认 parser.add_argument
will use GET params (location='args'
)。要获取 POST 数据,您需要在其参数中指定 location='form'
:
parser.add_argument('file', location='form')
我正在向 Flask Restful API
发送带有 cURL
的 POST 请求,因为:
curl -X POST -H 'Content-Type: text/csv' -d @trace.csv http://localhost:5000/upload
我无法从此请求中读取此数据,或者我不知道如何读取数据。下面是我对 API
:
class ForBetaAndUpload(Resource):
def post(self, kind='quotes'):
parser = reqparse.RequestParser()
parser.add_argument('file')
args = parser.parse_args()['file']
print(args) #Prints: Null
api.add_resource(ForBetaAndUpload, '/upload', endpoint='upload')
if __name__ == "__main__":
app.run(debug=True)
如何读取我用 cURL
发送的 csv 文件数据。非常感谢你的帮助。
默认 parser.add_argument
will use GET params (location='args'
)。要获取 POST 数据,您需要在其参数中指定 location='form'
:
parser.add_argument('file', location='form')