Closed OlafRadicke closed 9 years ago
I think it's just that your request is wrong. When you use the data
keyword we send the data as application/x-www-form-urlencoded data, not as JSON. Try using the json
keyword, like this:
import requests
request_uri = "http://127.0.0.1:5984/kochrezepte/pesto_alla_genovese_4"
json_doc = '{"titel":"Pesto alla genovese","zutaten": ["Basilikum","Knoblauch","Pinienkerne","Käse","Öl","Salz","Pfeffer"], "garzeit": 15 }'
respon = requests.put(request_uri, auth=("olaf", "olaf"), json=json_doc)
Hm, yes it's work...
[or@prag ~]$ python3 Python 3.4.1 (default, Nov 3 2014, 14:38:10) [GCC 4.9.1 20140930 (Red Hat 4.9.1-11)] on linux Type "help", "copyright", "credits" or "license" for more information.
import requests request_uri = "http://127.0.0.1:5984/kochrezepte/pesto_alla_genovese_10" headers = {'content-type': 'application/json'} json_doc = '{"titel":"Pesto alla genovese","zutaten": ["Basilikum","Knoblauch","Pinienkerne","Käse","Öl","Salz","Pfeffer"], "garzeit": 15 }' import json respon = requests.put(request_uri, auth=("olaf", "olaf"), json=json.loads(json_doc)) print(respon.text) {"ok":true,"id":"pesto_alla_genovese_10","rev":"1-4367a12038ab5809395199002de7e76d"}
But i can't not find the documentation of this cool feature. And if I look in the sources: https://github.com/kennethreitz/requests/blob/master/requests/api.py than I can only find "data=None". How could I find the?
Thank you
Olaf
You can find it here. You can also find it in the documentation.
Thank you. That is very helpful.
Hi, I get trouble with german umlauts in my json requests. An example:
Now without umlauts:
With curl I don't get errors:
CouchDB say:
So it's look like a unicode issue. Is my Python code wrong or the requests lib?
Thank you Olaf (from germany, augsburg)