1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Flask not accepting form

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to send to a flask app a simple form from python, with this requests:

    r = requests.post('http://x.x.x.x/Files',data = {
    'FileName': filename,
    'Mode' : 'Add'
    })


    flask app is handling it by this way:

    api.add_resource(GetFiles, '/Files')
    class GetFiles(Resource):
    def post(self):
    args = ParseArgs.parse_args()
    if '.txt' not in args['FileName']:
    FileName = f'{args["FileName"]}.txt'
    else:
    FileName = args['FileName']


    but I can't understand why, on every single request I am getting this response:

    { "message": "Did not attempt to load JSON data because the request Content-Type was not 'application/json'." }

    I tried by setting application-json as content-type but with this result: { "message": "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)" } in fact it wouldn't have made much sense since I'm submitting a form, but at least I tried.

    I don't really understand why, I've used this app several times and it never did before, I don't know if it could be due to a new flask update since I just moved to another server and I'm using a docker container.

    Thanks in advance for the help.

    Continue reading...

Compartilhe esta Página