Flask Restful - get sub element with reqparse

Asked

Viewed 62 times

0

I’m setting up an API in Flask and the request is as follows:

Request: http://127.0.0.1:5000/integra

json = {"recev": {"doc":"123456"} }

I’m trying to get the key value "doc", but to no avail:

from flask_restful import Resource, reqparse 

class Processa(Resource):

    def post(self):

        argumentos = reqparse.RequestParser()
        argumentos.add_argument('recev')

        dados = argumentos.parse_args()
        vdoc = dados{'doc':dados:['doc']}

        return vdoc, 200

1 answer

0

Solved, I removed the reqparse and redid the code

from flask import Flask, jsonify, request

@app.route('/recebe', methods=['POST'])
def recebeReq():
    req = request.get_json()
    for elem in req:
       doc= (req['recev']['doc'])
       print(doc)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.