我正在尝试使用python中的请求模块与休息服务器进行通信
这就是我想要做的事情:
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'
我该如何解决这个问题? 感谢
答案 0 :(得分:1)
尝试将标题更改为:
headers = {'Accept': 'application/json; charset=UTF-8'}
upd :我认为最正确的标题是:
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}