在在線服務中,javascript正在使用新的表單數據來獲取圖像,然後通過簡單的api調用通過此代碼檢索對象。python 400錯誤請求POST請求
function sendSearchImage(form) {
console.log(">>> sendSearchImage");
var image = new FormData();
image.append('refImage', readFile);
$.ajax({
type: 'post',
url: instore_home + '/products/query',
contentType: false,
processData: false,
data: image,
success: function (response) {
console.log("<<< " + JSON.stringify(response));
showQueryResults(response);
//alert("Ref image successfully added: code " + response.refImgId);
//alert(JSON.stringify(response));
//window.location.reload();
}
});
return false;
}
我想,而不是調用python中相同的API,但我不斷收到400:錯誤的請求的響應,這是我的代碼到目前爲止
files = {'refImage': ('1.jpg', open(os.getcwd()+"/images/1.jpg", "rb"), 'image/jpeg')}
headers = {"Content-Type":"multipart/form-data", "User-Agent" : "Mozilla/5.0"}
r = requests.post('Url', headers=headers, data=files)
有人能告訴我以哪種方式我應該通過數據獲得良好的迴應?
我試着按建議做,但沒有改變,我改變了一些帖子的格式,以儘可能相似的http身體請求,但我其實沒有文檔 – Lukepell