Amazon MWS SubmitFeed Content-MD5 HTTP标头与Amazon计算的Content-MD5不匹配 [英] Amazon MWS SubmitFeed Content-MD5 HTTP header did not match the Content-MD5 calculated by Amazon

查看:240
本文介绍了Amazon MWS SubmitFeed Content-MD5 HTTP标头与Amazon计算的Content-MD5不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题并不是新问题,但是我得到的所有解决方案都在PHP中,或者我的问题与此不同.

I know this question is not new but all the solution I get for this are in PHP or my issue is different from them.

我正在使用MWS feed API提交价格和数量更新的平面文件,并始终出现以下错误:

I am using MWS feed API to submit flat file for Price and Quantity Updates and always get the following error:

您为供稿传递的Content-MD5 HTTP标头与 我们为您的供稿计算的Content-MD5

the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed


我想在这里问3个问题:-

  1. ContentMD5Value参数是doc中提供的可选参数,但是如果我未通过该参数,它将表示您必须输入ContentMD5Value.

  1. ContentMD5Value parameter is optional as given in doc, but if i not passed that than it will say that you must enter ContentMD5Value.

与doc中提供给我们的ContentFeed一样. Amazon为该文件创建contentMD5,然后将该contentMD5值与我们发送给Amazon的contentMD5值进行比较.
如果两者都匹配,则确定,否则将引发错误.但是,如果我不发送文件,那么同样的错误也会导致MD5不匹配.那怎么可能呢?他们要为哪个文件计算MD5?因为我尚未在ContentFeed中发送文件.

As in doc the ContentFeed which we are given to Amazon. Amazon create contentMD5 for that file and then compares that contentMD5 value with the contentMD5 value we send to Amazon.
If both match then OK, otherwise it will throw an error. But if suppose I will not send the file then also the same errors come that MD5 does not match. How is that possible? Which file are they calculating the MD5 for? Because I haven't send the file in ContentFeed.

如果我在标头和参数中发送contentMD5并在正文中发送ContentFeed,我仍然会收到错误消息.

If I send the contentMD5 in a header as well as parameter and sending the ContentFeed in body, I still get the error.

注意:-我正在使用请求模块在标头和参数中发送contentMD5,并使用该参数计算签名,然后将contentFeed传递到正文中.

Note:- I am sending the contentMD5 in a header as well as in a parameters in form using request module and also calculating the signature with that and then pass the contentFeed in body.

我正在使用JavaScript(流星),我使用crpyto模块计算md5.
首先,我认为我的md5错误,但是随后我尝试了一个在线网站,该网站将为我提供md5的文件md5.

I am using JavaScript (Meteor), I calculate the md5 using the crpyto module.
First, I think that my md5 is wrong but then I tried with an online website that will give me the md5 for a file the md5.

我的文件是:

MD5值:d90e9cfde58aeba7ea7385b6d77a1f1e
Base64Encodevalue:ZDkwZTljZmRlNThhZWJhN2VhNzM4NWI2ZDc3YTFmMWU =

MD5 value: d90e9cfde58aeba7ea7385b6d77a1f1e
Base64Encodevalue: ZDkwZTljZmRlNThhZWJhN2VhNzM4NWI2ZDc3YTFmMWU=

我从价格和数量更新"中下载的平面文件:-

The flat file I downloaded from for Price and Quantity Updates:-

https://sellercentral.amazon.in/gp/help/13461?ie=UTF8&Version=1&entries=0&

我还通过在计算签名时给出ContentMD5Value来计算签名.

I calculated the signature also by giving ContentMD5Value while calculating the signature.

FeedType:'_ POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA _'

FeedType:'_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_'

此外,我阅读了有关在标头中传递MD5-标头并还作为参数发送的文档.

As, I read documentation for that I passed the MD5-header in headers and also send as parameter.

Amazon文档说:

Amazon doc says:

以前,Amazon MWS接受MD5哈希作为Content-MD5标头 而不是参数.将其作为参数传递可确保MD5 值是方法签名的一部分,可以防止任何人使用 网络以防止篡改供稿内容.

Previously, Amazon MWS accepted the MD5 hash as a Content-MD5 header instead of a parameter. Passing it as a parameter ensures that the MD5 value is part of the method signature, which prevents anyone on the network from tampering with the feed content.

Amazon MWS仍将接受Content-MD5标头,无论是否 包含ContentMD5Value参数.如果标题和参数 被使用,并且它们不匹配,您将收到一个 InvalidParameterValue错误.

Amazon MWS will still accept a Content-MD5 header whether or not a ContentMD5Value parameter is included. If both a header and parameter are used, and they do not match, you will receive an InvalidParameterValue error.

我正在使用request模块处理HTTP请求.

I am using the request module for http requests.

我正在以请求模块的形式传递所有必需的密钥,卖方ID等,并在正文中传递FeedContent.

I am passing all the required keys, seller id, etc. in form of request module and passing the FeedContent in body.

我尝试按以下方式发送文件:

submitFeed的方法是:-

submitFeed : function(){
    console.log("submitFeedAPI running..");
    app  = mwsReport({auth: {sellerId:'A4TUFSCXD64V3', accessKeyId:'AKIAJBU3FTBCJUIZWF', secretKey:'Eug7ZbaLljtrnGKGFT/DTH23HJ' }, marketplace: 'IN'});
    app.submitFeedsAPI({FeedType:'_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_'},Meteor.bindEnvironment(function(err,response){
        if(err){
            console.log("error in submit feed...")
            console.log(err)
        }
        else{
            console.log("suuccess submit feed....")
            console.log(response);
        }
    }))

调用Amazon SubmitFeedAPI的方法是:-

    var submitFeedsAPI =  function(options, callback){
        console.log("submitFeedsAPI running...");
    var fileReadStream = fs.createReadStream('/home/parveen/Downloads/test/testting.txt');
        var contentMD5Value = crypto.createHash('md5').update(file).digest('base64');

    var reqForm = {query: {"Action": "SubmitFeed", "MarketplaceId": mpList[mpCur].id, "FeedType":options.FeedType,"PurgeAndReplace":false,"ContentMD5Value":contentMD5Value}}; 
            mwsReqProcessor(reqForm, 'submitFeedsAPI', "submitFeedsAPIResponse", "submitFeedsAPIResult", "mwsprod-0000",false,file, callback);
    }


also try

    var fileReadStream = fs.createReadStream('/home/parveen/Downloads/test/testting.txt');
    var base64Contents = fileReadStream.toString('base64');
    var contentMD5Value = crypto.createHash('md5').update(base64Contents).digest('base64');

mwsReqProcessor函数如下:-

 mwsReqProcessor = function mwsReqProcessor(reqForm, name, responseKey, resultKey, errorCode,reportFlag,file, callback) {

        reqOpt = {
            url: mwsReqUrl,
            method: 'POST',
            timeout: 40000,
            body:{FeedContent: fs.readFileSync('/home/parveen/feedContentFile/Flat.File.PriceInventory.in.txt')},
            json:true,
            form: null,
            headers: {
                // 'Transfer-Encoding': 'chunked',
                //'Content-Type': 'text/xml',
               // 'Content-MD5':'ZDkwZTljZmRlNThhZWJhN2VhNzM4NWI2ZDc3YTFmMWU=',
                // 'Content-Type': 'text/xml; charset=iso-8859-1'
                'Content-Type':'text/tab-separated-values;charset=UTF-8'
            },
        }
        reqOpt.form = mwsReqQryGen(reqForm);
        var r = request(reqOpt, function (err, res, body){
            console.log(err)
            console.log(res)
        })
        // var form  = r.form();
        //form.append('FeedContent',fs.createReadStream('/home/parveen/feedContent//File/Flat.File.PriceInventory.in.txt'))
    }

mwsReqQryGen生成方法:-

mwsReqQryGen = function mwsReqQryGen(options) {
    var method     = (options && options.method) ? ('' + options.method) : 'POST',
        host       = (options && options.host)   ? ('' + options.host)   : mwsReqHost,
        path       = (options && options.path)   ? ('' + options.path)   : mwsReqPath,
        query      = (options && options.query)  ? options.query         : null,


        returnData = {
          "AWSAccessKeyId": authInfo.accessKeyId,
          "SellerId": authInfo.sellerId,
          "SignatureMethod": "HmacSHA256",
          "SignatureVersion": "2",
          "Timestamp": new Date().toISOString(),
           "Version":"2009-01-01",
        },
        key;

    if(query && typeof query === "object")
      for(key in query)
        if(query.hasOwnProperty(key)) returnData[key] = ('' + query[key]);

    if(authInfo.secretKey && method && host && path) {

      // Sort query parameters
      var keys = [],
          qry  = {};

      for(key in returnData)
        if(returnData.hasOwnProperty(key)) keys.push(key);

      keys = keys.sort();
      for(key in keys)
        if(keys.hasOwnProperty(key)) qry[keys[key]] = returnData[keys[key]];
      var sign = [method, host, path, qs.stringify(qry)].join("\n");
      console.log("..................................................")
      returnData.Signature = mwsReqSignGen(sign);

    }
//console.log(returnData); // for debug

return returnData;

};

我还尝试了以下操作:-

I also tried with following:-

reqOpt = {
    url: mwsReqUrl,
    method: 'POST',
    timeout: 40000,
    json:true,
    form: null,
    body:  {FeedContent: fs.createReadStream('/home/parveen/feedContentFile/Flat.File.PriceInventory.in.txt')},
    headers: {
        // 'Transfer-Encoding': 'chunked',
        //'Content-Type': 'text/xml',
       // 'Content-MD5':'ZDkwZTljZmRlNThhZWJhN2VhNzM4NWI2ZDc3YTFmMWU=',
        //   'Content-Type': 'text/xml; charset=iso-8859-1'
    },
}

我也尝试了不使用JSON的情况,并直接将文件读取流发送到 身体,即:

I also tried without JSON and directly send the file read stream in the body, i.e:

reqOpt = {
    url: mwsReqUrl,
    method: 'POST',
    timeout: 40000,
    form: null,
    body:  fs.createReadStream('/home/parveen/feedContentFile/Flat.File.PriceInventory.in.txt'),
    headers: {
        // 'Transfer-Encoding': 'chunked',
        //'Content-Type': 'text/xml',
     //   'Content-MD5':'ZDkwZTljZmRlNThhZWJhN2VhNzM4NWI2ZDc3YTFmMWU=',
        //   'Content-Type': 'text/xml; charset=iso-8859-1'
    },
}

但是每次都会出现相同的错误:

But same error comes every time:

您为供稿传递的Content-MD5 HTTP标头与 我们为您的供稿计算的Content-MD5

the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed

我想知道我做错了什么,或者使用请求模块提交Feed API和发送文件的正确方法是什么.

I want to know where I am doing wrong or what is the right way to submit feed API and sending the file using request module.

我也尝试使用MWS上给出的代码来生成MD5,但相同 每次都发生错误.

I also tried with the code given on MWS to generate the MD5 but same error occurred each time.

我的.txt文件如下:


sku price   quantity
TP-T2-00-M      2

非常感谢您的帮助

推荐答案

最后,我得到了如Ravi上面所述的解决方案. 实际上,我想为所有面临相同问题的所有人澄清以下几点:-

finally i got the solution as Ravi said above. Actually there are few points i want to clear here for you all who are facing the same issue:-

1)亚马逊市场 API文档未提供正确的信息和示例.甚至我猜文档也没有更新.就像在doc中一样,他们说ContentMD5Value参数值是可选的,这是doc的链接:-

1)Amazon marketplace API doc is not giving proper information and example. Even i guess the documentation is not updated . As in doc they said that ContentMD5Value parameter value is optional, here is the link for doc:-

http://docs.developer.amazonservices.com/en_US/feeds /Feeds_SubmitFeed.html

您可以在此处检查是否清楚地指出了该字段不是必填字段,但是如果您未通过该字段,则他们给出了必须通过内容MD5值的错误提示.

You can check there they clearly mention that the field is not required but if you not pass than they gives the error that you must pass content MD5 value.

那是错误的. ContentMD5是必填属性.

So that is wrong. ContentMD5 is required attribute.

2)他们在同一文档中说,您需要通过字段键名称(即FeedContent )中的xml或平面文件发送文件数据,格式为xml或平面文件.

2)They said in the same doc that you need to send file data weather its a xml or flat-file in the field key name i.e. FeedContent.

但这也不是必需的,您可以发送任何名称为no的文件 您需要为文件提供FeedContent密钥,而只需发送 文件流中.

But that is also not needed you can send the file with any name no need to give FeedContent key for the file you just need to send the file in stream.

3)它们将给出相同的错误,即contentMD5是否与您发送的文件不匹配,因为如果找不到文件,则与您发送的contentMD5不匹配.因此,如果遇到 ContentMD5不匹配错误,请检查以下内容:-

3)They will give the same error of contentMD5 not match weather you send file or not because if they not found file than the contentMD5 you send will not match to that. SO if you are getting the ContentMD5 not match error than check the following:-

1)检查是否正在为文件生成正确的MD5代码,可以通过在doc上给出的Java代码来检查是否正在生成正确的代码. 您可以从链接中获得它:-

1)Check that you are generating the right MD5 code for your file you can check whether you are generating the right code or not by there java code they given on doc . You can get that from the link:-

http://docs.developer.amazonservices.com/en_US/dev_guide /DG_MD5.html

2)不要相信在线网站会生成MD5哈希和base64编码.

2)Don't trust on online websites for generating the MD5 hash and base64 encoding.

3)如果您的MD5与从Java代码生成的MD5匹配,则他们给出的一件事显然表明您的MD5是正确的,因此无需对此进行更改.

3)If your MD5 is matched with the MD5 generated from Java code they given than one thing is clear that your MD5 is right so no need to change on that.

4)一旦您的MD5正确,此后也将出现相同的错误,即:-

4)Once your MD5 is correct and after that also if you get the same error that is:-

Amazon MWS SubmitFeed Content-MD5 HTTP标头与 亚马逊计算的Content-MD5

Amazon MWS SubmitFeed Content-MD5 HTTP header did not match the Content-MD5 calculated by Amazon

ContentMD5不匹配.您只需要检查文件上传机制即可. 因为现在您要发送到Amazon的文件不正确,或者您发送的方式不正确.

ContentMD5 not matched .Than you need to check only and only you file uploading mechanism. Because now the file you are sending to Amazon is not either correct or you are not sending it in the right way.

检查文件上传:-

要检查是否需要发送正确的文件,需要使用以下命令进行检查:-

1)您需要发送必填参数(例如SellerId,marketplaceId,AWSAccessKey等)作为查询参数.

1)You need to send the required parameters like sellerId, marketplaceId, AWSAccessKey etc as query params.

2)如果您使用的是node.js的请求模块,则需要以多部分形式将文件以表单数据的形式发送,而不是上面的Ravi给出的代码.

2)You need to send the file in the form-data as multipart , if you are using the request module of node.js than you can see the above code given by Ravi.

3)您只需将标头设置为:-

3)you need to set the header as only:-

内容类型":"application/x-www-form-urlencoded"

'Content-Type': 'application/x-www-form-urlencoded'

无需将标头发送为分块或制表符分隔等,因为我不再需要它们,它们甚至使我感到困惑,因为在某人写的地方使用此标头在其他地方写的人使用此标头. 最后,由于我愿意提交此API,所以我不需要任何标头,而无需application/x-www-form-urlencoded.

No need to send the header as chunked or tab separated etc because i don't need them any more they are even confuse me because somewhere someone write use this header on other place someone write use this header. So finally as i am abel to submit this API i didn't need any of the header rather than application/x-www-form-urlencoded.

示例:-

reqOpt = {
   url: mwsReqUrl,
   method: 'POST',
   formData: {
      my_file: fs.createReadStream('file.txt')
  },
  headers: {
     'Content-Type': 'application/x-www-form-urlencoded'
  },
qs: { }// all the parameters that you are using while creating signature.

用于创建contentMD5的代码为:-

var  fileData= fs.readFileSync('/home/parveen/Downloads/test/feed.txt','utf8');

var contentMD5Value = crypto.createHash('md5').update(fileData).digest('base64');

由于我面临的问题是因为我正在通过请求模块同时使用表单和表单数据,所以我将qs(查询字符串)的表单数据与表单数据中的文件转换为多部分.

As i am facing the issue that is because i am using form and form-data simultaneously via request module so i convert my form data with qs(query string) and file in form-data as multipart.

因此,您可以通过这种方式成功提交用于提交供稿的API.

So in this way you can successfully submit the API for submit feed.

任何查询都是最欢迎的 谢谢

Any queries are most welcome Thanks

这篇关于Amazon MWS SubmitFeed Content-MD5 HTTP标头与Amazon计算的Content-MD5不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆