在在线服务中,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