[Python] Can we include both JSON payload and CSV File using form-data in POSTMAN?

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to send a POST request to my Python Flask Server. I tried to send a CSV file using the form-data option of POSTMAN. It was successfully received by the Flask server.

    Now, I want to send a JSON payload along with the CSV file which will consist of the User credentials.

    I tried the below method but it does not seem to be working. Although, I am receiving the CSV file but the JSON is still not received by the Flask server.

    [​IMG]

    class Upload_File(Resource):

    def post(self):

    file_ = request.files['file']
    Q_data = pd.read_csv(file_, header=None, names=['Questions'])
    print(Q_data) # successfully displays file content
    data = request.get_json(force=True) # gives None

    EDIT


    The issue was with the Flask code. The working code is -

    class Upload_File(Resource):

    def post(self):

    file_ = request.files['file']
    Q_data = pd.read_csv(file_, header=None, names=['Questions'])
    print(Q_data) # successfully displays file content
    username = request.form.get('username') # modified
    password = request.form.get('password') # modified

    Continue reading...

Compartilhe esta Página