我知道这个问题不是新问题,但我得到的所有解决方案都在 PHP 中,或者我的问题与他们不同。
我正在使用 MWS 提要 API 提交价格和数量更新的平面文件,但总是收到以下错误:
the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed
我想在这里问 3 个问题:-
ContentMD5Value 参数是可选的,如 doc 中给出的,但如果我没有通过它就会说你必须输入 ContentMD5Value。
就像文档中的 ContentFeed 一样,我们将其提供给亚马逊。亚马逊为该文件创建 contentMD5,然后将该 contentMD5 值与我们发送给亚马逊的 contentMD5 值进行比较。
如果两者都匹配则OK,否则会抛出错误。但是如果假设我不会发送文件,那么同样的错误也会出现 MD5 不匹配。这怎么可能?他们为哪个文件计算 MD5?因为我没有在 ContentFeed 中发送文件。
如果我在 header 和参数中发送 contentMD5 并在正文中发送 ContentFeed,我仍然会收到错误消息。
注意:- 我正在使用请求模块在 header 和表单参数中发送 contentMD5,并使用该模块计算签名,然后传递 contentFeed 在正文中。
我正在使用 JavaScript (Meteor),我使用 crpyto 模块计算 md5。
首先,我认为我的 md5 是错误的,但后来我尝试了一个在线网站,该网站将为我提供 md5 文件的 md5。
我的文件是:
MD5 value: d90e9cfde58aeba7ea7385b6d77a1f1e
Base64Encodevalue: ZDkwZTljZmRlNThhZWJhN2VhNzM4NWI2ZDc3YTFmMWU=
我下载的用于价格和数量更新的平面文件:-
https://sellercentral.amazon.in/gp/help/13461?ie=UTF8&Version=1&entries=0&
我还通过在计算签名时给出 ContentMD5Value 来计算签名。
FeedType:'_POST_FLAT_FILE_PRICEANDQUANTITYONLY_UPDATE_DATA_'
因为,我阅读了有关我在 header 中传递 MD5 header 并作为参数发送的文档。
亚马逊文档说:
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 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 请求。
我以请求模块的形式传递所有必需的 key 、卖家 ID 等,并在正文中传递 FeedContent。
我尝试按如下方式发送文件:
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);
}
}))
调用亚马逊 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;
};
我也尝试了以下方法:-
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直接发送文件读取流在 body ,即:
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'
},
}
但每次都会出现同样的错误:
the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed
我想知道我在哪里做错了,或者使用请求模块提交提要 API 和发送文件的正确方法是什么。
我也尝试使用 MWS 上给出的代码来生成 MD5 但相同 每次都会出错。
我的.txt文件如下:
sku price quantity TP-T2-00-M 2
非常感谢任何帮助
最佳答案
最后我得到了 Ravi 上面所说的解决方案。 实际上,我想在这里为所有面临相同问题的人澄清几点:-
亚马逊商城API 文档未提供正确信息和示例。即使我猜文档没有更新。正如在文档中,他们说 ContentMD5Value 参数值是可选的 on this page
您可以在那里查看,他们清楚地提到该字段不是必需的,但如果您没有通过,他们会给出错误,即您必须通过内容 MD5 值。
So that is wrong. ContentMD5 is required attribute.
他们在同一个文档中说,您需要在字段键名(即
But that is also not needed you can send the file with any name no
need to give FeedContent 中发送 xml 或平面文件文件数据。
FeedContent key for the file you just need to send the
file in stream.
他们会给出相同的错误,即 contentMD5 与您发送文件的天气不匹配,因为如果他们没有找到文件而不是您发送的 contentMD5 将不匹配。因此,如果您遇到 ContentMD5 不匹配错误,请检查以下内容:-
检查您是否正在为您的文件生成正确的 MD5 代码,您可以通过他们在 doc 上提供的 java 代码检查您是否正在生成正确的代码。你可以从 this link 获得。
不要相信在线网站会生成 MD5 哈希和 base64 编码。
如果您的 MD5 与他们给出的 Java 代码生成的 MD5 匹配,那么一件事很明显您的 MD5 是正确的,因此无需更改。
一旦你的 MD5 是正确的,然后如果你得到同样的错误,那就是:-
Amazon MWS SubmitFeed Content-MD5 HTTP header did not match the Content-MD5 calculated by Amazon
ContentMD5 不匹配。您只需要检查文件上传机制。 因为现在您发送到亚马逊的文件不正确,或者您发送的方式不正确。
要检查您是否发送了正确的文件,您需要检查以下内容:-
您需要将所需的参数(如 SellerId、marketplaceId、AWSAccessKey 等)作为查询参数发送。
如果你使用 node.js 的 request 模块,你需要将文件作为 multipart 发送到 form-data 中,你可以看到上面 Ravi 给出的代码。
你需要将header设置为only:-
'Content-Type': 'application/x-www-form-urlencoded'
无需将标题以分 block 或制表符分隔等形式发送,因为我不再需要它们,它们甚至让我感到困惑,因为在某个地方有人写使用这个标题,而在其他地方有人写使用这个标题。 所以最后我可以提交这个 API 我不需要任何标题而不是 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.
创建内容MD5的代码是:-
var fileData= fs.readFileSync('/home/parveen/Downloads/test/feed.txt','utf8');
var contentMD5Value = crypto.createHash('md5').update(fileData).digest('base64');
因为我面临的问题是因为我通过请求模块同时使用表单和表单数据,所以我将表单数据与 qs(查询字符串)和表单数据中的文件转换为多部分。
那么这样就可以成功提交提交feed的API了。
关于node.js - 亚马逊 MWS SubmitFeed Content-MD5 HTTP header 与亚马逊计算的 Content-MD5 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40180070/
是否可以创建8个字符长的md5散列? 最佳答案 MD5创建16字节的哈希值。您当然可以将字符串裁剪为八个字符,如myString[0..7]一样,但请注意,这不再是有效的MD5散列。 关于ruby-我可以创建长度为8的md5哈希吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5854208/
我正在尝试使用Nokogiri和XPath从网站上抓取图像,但到目前为止收效甚微。对于其HTML具有img和src的典型网站,我可以使用:tmp2=Nokogiri::HTML(open(site_url))tmp2.xpath("//img/@src").eachdo|src|...dowhateverend但是,某些网站(如Amazon和eBay)仅使用JavaScript触发特定图像。如果我查看代码,我可以看到数组中的数据。例如,来自Amazon:P.when('jQuery','cf').execute(function($,cf){P.load.js('http://z-ec
有没有一种用Ruby或Python访问亚马逊搜索结果(给定查询)的好方法?我一直在寻找API,发现了一个产品广告API,它似乎与搜索不同。我宁愿不必在给定查询(嵌入在url中)的情况下抓取亚马逊搜索网页。 最佳答案 我已经使用AmazonAPI好几年了,我承认他们似乎试图隐藏他们在使用他们的常规附属产品(例如AmazonSearch)所做的事情,就好像他们不希望您使用该API或者至少让它变得困难。因此,在您的附属仪表板中,单击顶部的“产品API”选项卡。接下来,您需要创建公钥和私钥。如果未创建和设置这些,您将无法访问API。另请注意
我有以下用于将本地文件上传到AmazonS3存储桶的代码:require'aws/s3'moduleAmazonS3defself.upload_file(local_file)bucket_name="bucketfortest"s3=AWS::S3.new(:access_key_id=>ENV["AMAZON_ACCESS_KEY"],:secret_access_key=>ENV["AMAZON_SECRET_KEY"])key=File.basename(local_file)amazon_object=s3.buckets[bucket_name].objects[key]
有没有人有一个很好的Ruby脚本来使用他们的API在Amazon上查找书籍(或其他产品)? 最佳答案 我一直在使用Amazon/ECS取得了巨大的成功。重要的一点是它不是GPL的(而Ruby/AWS似乎是),所以如果它对您的情况很重要,请小心。这是一个示例:require'amazon/ecs'#defaultoptions;willbecamelizedandconverted#toRESTrequestparameters.Amazon::Ecs.options={:aWS_access_key_id=>[youraccessk
使用Google+Bing并没有给出应该是一个简单问题的答案:您应该如何使用Ruby中的HMAC模块来创建带MD5的HMAC(使用secret)?HMAC文档看起来非常薄。谢谢! 最佳答案 这应该是最简单的方法:OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('md5'),secret_key,your_data) 关于ruby-on-rails-如何在Ruby中使用HMAC模块创建MD5哈希?,我们在StackOverflow上找到一个
只是想要一些关于使用亚马逊API对他们的数据库进行检查以退回产品的建议。例如,添加了一张DVD,我希望返回一个链接到亚马逊上的产品的链接。我遇到过一些gem,例如ruby-aws,根据您的经验,哪些是最好和最容易使用的?此外,在可用资源最多的情况下,我完全是Rails菜鸟!所以我需要很多帮助。谢谢标记 最佳答案 如果您需要来自亚马逊产品广告API的产品详细信息,请尝试Vacuum.如果您只需要构建返回亚马逊的链接,请将产品的十位数ASIN附加到:http://www.amazon.com/dp/[ASINgoeshere]
我在这里遇到了一些奇怪的事情。我有一个“身份验证器”,它依赖于ND5来散列我们作为密码匹配的特定字符串。我运行测试时出现的问题是:NoMethodError:undefinedmethod`md5'for#./models/authenticators/billing.rb:63:in`validate'./routes/login.rb:166:in`block(2levels)in'./routes/login.rb:158:in`each'./routes/login.rb:158:in`blockin'(eval):2:in`click_button'./features/st
我正在RubyonRails3.1项目中编写一个富含Javascript的应用程序,并将Handlebars用于我的JS模板框架。我正在尝试找出一种方法,将Assets的MD5摘要(在生产中的Assets预编译期间生成)动态附加到我的Handlebars模板内的标签中。我希望有一个以Assets路径为键、以MD5摘要为值的散列,但我一直找不到。一个理想的解决方案是将哈希值从Ruby传递到Javascript并定义一个Handlebars助手,它会自动将MD5摘要附加到Assets的“src”属性。有没有人尝试过做类似的事情?必须有一种方法可以在Rails中使用Javascript模板并
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Isitpossibletodecryptmd5hashes?我在Ruby中这样做:Digest::MD5.hexdigest("Jose")并得到“70483b6e100c9cebbffcdc62dea07eda”但是,我如何将它解密回“Jose”?