Giter Site home page Giter Site logo

Comments (4)

johtso avatar johtso commented on April 28, 2024 1

I took a look at what was going on, and it seems that the cause of the problem is the Flask response form-data MultiDict being converted to json.

It behaves like a normal dict thus all dict functions will only return the first value when multiple values for one key are found.

So by converting it to json, multiple values for the same key are lost.

One solution would be to put multiple values for the same keys into lists, thus making them representable in json:

form = {}
for key in request.form.keys():
    values = request.form.getlist(key)
    if len(values) == 1:
        form[key] = values[0]
    else:
        form[key] = values

from httpbin.

kennethreitz avatar kennethreitz commented on April 28, 2024

Correct. This is what we do in requests (except reverse).

from httpbin.

piotr-dobrogost avatar piotr-dobrogost commented on April 28, 2024

That's what to_dict method does:

to_dict(flat=True)
    Return the contents as regular dict. If flat is True the returned dict will only have the first item present, if flat is False all values
will be returned as lists.

from httpbin.

johtso avatar johtso commented on April 28, 2024

Thanks piotr, didn't see that method.

from httpbin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.