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>

<blockquote>
  <p>@Mike Tung</p>
  
  <p>...</p>
  
  <p>You can make your life a bit easier by using requests</p>
  
  <p>...</p>
</blockquote>

<p><strong>How do you pass files to the requests <code>json</code> kwarg ? As file handles ? Or Strings ?</strong></p>

<p>When I try this,</p>

<pre><code>import requests
url = 'http://localhost:5000/tests'
data = {
    'icons': [
        open('/home/test/git-projects/test.com/backend/fixtures/media/test1.jpg').read(), #  If I pass the handle, it fails as well.
        open('/home/test/git-projects/test.com/backend/fixtures/media/test2.jpg').read()
    ]
}
r = requests.post(url, json=data)

/home/test/venvs/test/bin/python2.7 /home/test/git-projects/test.com/backend/__main__.py
    /home/test/venvs/test/local/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.pymongo is deprecated, use flask_pymongo instead.
      .format(x=modname), ExtDeprecationWarning
    /home/test/venvs/test/local/lib/python2.7/site-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.sentinel is deprecated, use flask_sentinel instead.
      .format(x=modname), ExtDeprecationWarning
    Traceback (most recent call last):
      File "/home/test/git-projects/test.com/backend/__main__.py", line 43, in &lt;module&gt;
        r = requests.post(url, json=data)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/requests/api.py", line 109, in post
        return request('post', url, data=data, json=json, **kwargs)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
        response = session.request(method=method, url=url, **kwargs)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/requests/sessions.py", line 451, in request
        prep = self.prepare_request(req)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/requests/sessions.py", line 382, in prepare_request
        hooks=merge_hooks(request.hooks, self.hooks),
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/requests/models.py", line 307, in prepare
        self.prepare_body(data, files, json)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/requests/models.py", line 428, in prepare_body
        body = json_dumps(json)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/simplejson/__init__.py", line 380, in dumps
        return _default_encoder.encode(obj)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/simplejson/encoder.py", line 275, in encode
        chunks = self.iterencode(o, _one_shot=True)
      File "/home/test/venvs/test/local/lib/python2.7/site-packages/simplejson/encoder.py", line 357, in iterencode
        return _iterencode(o, 0)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte

    Process finished with exit code 1
</code></pre>

python list curl media eve