Python eve - POST a list media files with curl command failed with 422 error
<p>I use python-eve to build my RESTful API, I set a endpoint 'risks' in settings.py, like so:</p>

<pre><code>risks = {
    'schema': {
        'description': {
            'type': 'string',
            'required': True,
        },
        'pic': {
            'type': 'list',
            'schema': {
                'type': 'media',
            }
        },
    }
}
</code></pre>

<p>I try curl command to POST two jpg files to 'pic' field like so:</p>

<pre><code>curl -F "description=something" -F "pic=@test1.jpg,test2.jpg" http://127.0.0.1:8080/risks
</code></pre>

<p>but get 422 error like this:</p>

<pre><code>{"_status": "ERR", "_issues": {"pic": "must be of list type"}, "_error": {"message": "Insertion failure: 1 document(s) contain(s) error(s)", "code": 422}}%
</code></pre>

<p>what can I do, I tried just one media(not list type),It's no problem,why?
Can someone help me?</p>

<p>When you access the <code>risks</code> endpoint you need to supply the right datatypes in order for the resource endpoint to work. It complains about the pic you send because that is still a string and not a list.</p>

<p>You can make your life a bit easier by using <code>requests</code></p>

<pre><code>import requests

url = 'http://127.0.0.1:8080/risks'
data = {description : 'something', 'pic' : ['a','b','c','d']}
r = requests.post(url, json=data)
</code></pre>

python list curl media eve