pyeve / eve-demo

A fully functional REST Web API. Powered by Eve.
Other
256 stars 78 forks source link

Requests don't seem to be able to send dictionaries to eve #14

Closed rethore closed 9 years ago

rethore commented 9 years ago

Hi, I'm trying to use your demo example with the requests library. It does work fine when sending just the firstname and lastname. But not when sending the location dictionary.

payload = {'firstname': 'lapin', 
           'lastname': 'lauvages3',
           'location': {'address': 'blabla', 'city': 'Paris'}}
r = requests.post('http://127.0.0.1:5000/people', data=payload)
print r.text
print r.url
{"_status": "ERR", "_issues": {"location": "must be of dict type"}, "_error": {"message": "Insertion failure: 1 document(s) contain(s) error(s)", "code": 422}}
http://127.0.0.1:5000/people

But it work fine with curl. I guess I'm missing something in the request code, but I really can't figure it out.

curl -d '{"firstname": "lapin", "lastname": "lauvage3", "location": {"address": "blabla", "city": "Paris"}}'  -H 'Content-Type: application/json'   http://127.0.0.1:5000/people
{"_updated": "Tue, 14 Apr 2015 08:14:01 GMT", "_links": {"self": {"href": "people/552ccc49bd84780289f8a607", "title": "person"}}, "_created": "Tue, 14 Apr 2015 08:14:01 GMT", "_status": "OK", "_id": "552ccc49bd84780289f8a607", "_etag": "88fe38b3d03967b1746c65a37acfb35531f87088"}

Do you have any idea what I'm doing wrong? Thanks!

rethore commented 9 years ago

I have figured it out:

payload = {'firstname': 'lapin', 
           'lastname': 'lauvages4',
           'location': {'address': 'blabla', 'city': 'Paris'}}
headers = {'Content-type': 'application/json; charset=utf-8'}
r = requests.post('http://127.0.0.1:5000/people', data=json.dumps(payload), headers=headers)
print r.text
print r.url
{"_updated": "Tue, 14 Apr 2015 08:35:52 GMT", "_links": {"self": {"href": "people/552cd168bd84780289f8a609", "title": "person"}}, "_created": "Tue, 14 Apr 2015 08:35:52 GMT", "_status": "OK", "_id": "552cd168bd84780289f8a609", "_etag": "e8c53dd08bc953757ef26af0d3c46e4eecc8e2a9"}
http://127.0.0.1:5000/people
nicolaiarocci commented 9 years ago

:+1: