【发布时间】:2017-09-21 20:17:25
【问题描述】:
我在转换嵌套字典形式的有效负载数据以使用 Python 请求模块将其作为 POST 请求的数据传递时遇到问题。表单数据如下:
payload = {'request': {
'appkey': "936725A4-7D9A-11E5-81AC-86EC8D89CD5A"},
'formdata':{
'currency':'US',
'dataview':'store_default',
'distinct':'_distance, clientkey',
'geolocs':{
'geoloc':[{
'0':{
'address1':'',
'addressline':'19128, PA',
'city':'Philadelphia',
'country':'US',
'latitude':'40.0532987',
'longitude':'-75.23040379999998',
'postalcode':'19128',
'province':'',
'state':'PA'}}]
},
'google_autocomplete':'true',
'limit':'250',
'nobf':'1',
'searchradius':'15|25|50|100|250|350|450|550|650|750|850|950',
'true':'1',
'where':{'partner_reseller': {'eq':'1'}}}
}
r = requests.post(url,data=simplejson.dumps(payload),headers=header)
result = simplejson.loads(str(r.content))
有人可以帮助我整理结构并指出我所写内容中的错误。我不断收到以下错误:
{'code': 1008,
'response': {'message': 'The submitted XML is not properly formed'}}
非常感谢您的帮助。谢谢。
【问题讨论】:
-
这是什么 API?有文档吗?如果是公共 API,您点击的 url 会有所帮助
-
您在消息中收到了“提交的 XML”,所以 api 请求可能是 XML 数据?或者你应该在你的标题中设置
Content-Type到application/json。如heinst所说,如果可以的话,请给我们文档或API的名称。 -
@rsz: 我已经在标题中将 'content-type' 设置为 'application/json'
标签: python json dictionary post python-requests