我無法在嵌套詞典的形式變換有效載荷數據以將其傳遞作爲使用Python請求模塊POST請求數據。表格數據如下:嵌套字典到JSON進行POST請求的Python
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會有所幫助。 – heinst
你在消息中獲得了「提交的XML」,所以api請求的可能是XML數據?或者你應該在你的頭文件中設置'Content-Type'爲'application/json'。如上所述,如果可以,請給我們文檔或API的名稱。 – rsz
@rsz:我已經設置了「內涵式」於首 –