Reputation: 33213
I am trying to use requests module in python to communicate with a rest server
This is what I am trying to do:
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
data = {'foo':'foo','bar':'bar'}
r = requests.post("http://localhost:8080/foo",headers=headers,data=json.dumps(data))
print r.text
u'Resource representation is only available with these Content-Types:\napplication/json; charset=UTF-8'
How do I resolve this? Thanks
Upvotes: 0
Views: 1032
Reputation: 8067
Try to change headers to:
headers = {'Accept': 'application/json; charset=UTF-8'}
upd: I think the most correct headers would be:
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
Upvotes: 2