无法使用请求库python发出post请求

无法使用请求库python发出post请求,python,Python,我正在尝试使用python中的请求模块与rest服务器通信 这就是我想做的: 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'Resourc

我正在尝试使用python中的请求模块与rest服务器通信

这就是我想做的:

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'
我如何解决这个问题?
谢谢尝试将标题更改为:

headers = {'Accept': 'application/json; charset=UTF-8'}
upd:我认为最正确的标题应该是:

headers = {'Content-type': 'application/json', 'Accept': 'application/json'}

根据您的建议,我得到了以下响应:“u”资源表示仅适用于以下内容类型:\ntext/plain;charset=UTF-8\ntext/plain“我尝试了以下标题={'Content-type':'application/json','Accept':'text/plain;charset=UTF-8'}并且它给出了服务器无法使用
headers={'Accept':'application/json'}
或不使用此选项及时响应您的请求。。我得到u“请求内容类型有问题:\n预期的'application/json'”请尝试此标题:
headers={'Content-Type':'application/json;charset=UTF-8'}