Python Eve - POST payload containing a list
Question: I am having trouble with the `list` type in my schemas. Whenever I try to
POST, I get a 422 response stating 'must be of list type'. Below is a simple
example that produces this problem.

    
    
    from eve import Eve
    
    people = {
        'schema': {
            'tests': {
                'type': 'list',
                'schema': {
                    'type': 'string'
                },
                'required': True,
            }
        },
        'resource_methods': ['GET', 'POST'],
    }
    
    settings = {
        'DOMAIN': {
            'people': people
        }
    }
    app = Eve(settings=settings)
    
    if __name__ == '__main__':
        app.run()
    

Then when you POST to the people endpoint with the following:

    
    
    import requests
    
    url = "http://localhost:5000/people"
    
    person = {
        "tests": ['a', 'b'],
    }
    
    r = requests.post(url, data=person)
    print(r.json())
    

You get the 422 response. When I debug this, it looks like the Eve application
has received the `tests` parameter as just a string, `'a'`, rather than the
whole list. From what I can see in the Eve tests on GitHub, this seems to be
the right way to make the request, so I can only assume I'm making a mistake
in setting up the resource/schema?

Thanks.


Answer: If you print `request.POST`, you would see `UnicodeMultiDict([('tests', u'a'),
('tests', u'b')])`. Fix to this would be to use `json object` for your `post`.

    
    
    person = json.dumps({
        "tests": ['a', 'b'],
    })
    
    r = requests.post(url, json=person)
    print(r.json())
    

Or in your case, you will have to somehow tweak your POST request at API end
to get a list as:- `request.POST.getall('tests')` and then proceed.

Please check [using json in POST request](http://www.python-
requests.org/en/latest/user/quickstart/#more-complicated-post-requests). Also
while using `json`, json.dumps may not be required, the dictionary will be
`jsonified` automatically.

