gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:20:28 27 4
gpt4 key购买 nike

我正在尝试在 Django (Python) 环境中使用 Amazon API 为产品设置最高价格。我已经通过计算 md5 函数解决了这个问题,该函数的值与 Amazon MWS Scratchpad 计算的值完全相同。

解决此问题后,我现在收到“您为您的供稿传递的 Content-MD5 HTTP header 与我们为您的供稿计算的 Content-MD5 不匹配”的错误消息。

我的代码如下:

feedTxt = '<?xml version="1.0" encoding="utf-8"?><AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Header><DocumentVersion>1.01</DocumentVersion><MerchantIdentifier>MERCH_ID</MerchantIdentifier></Header><MessageType>Price</MessageType><Message><MessageID>1</MessageID><Price><SKU>J1-1UKW-8Z03</SKU><MaximumSellerAllowedPrice currency="EUR">999</MaximumSellerAllowedPrice></Price></Message></AmazonEnvelope>'

feed = open('myXml.xml', mode='w+', buffering=-1, encoding='utf-8')
feed.write(feedTxt)
feed.close()

encodedFeed = feedTxt.strip().encode('utf-8')

md5 = hashlib.md5(encodedFeed).digest()
encodedMd5 = base64.b64encode(md5)
parsedMd5 = urllib.parse.quote(encodedMd5, safe='')

request_string = construct_strings(seller, '', 'SubmitFeed', '2009-01-01', args_dict) # this function defines the string to be signed and is working 100%, since I use it for all the other requests I do

feed = open('myXml.xml', mode='r', buffering=-1, encoding='utf-8')
myFile = {'file': feed}
response = requests.post(request_string, headers = {'Content-MD5': encodedMd5, 'Content-Type': 'text/xml'}, files = myFile)
feed.close()

这是我在 stackOverflow 中提出的第一个问题。我很感激你能给我的任何提示。

谢谢!

最佳答案

只是告诉你我已经解决了我的问题。我发现提要不是作为文件发布,而是在正文(“数据”字段)中发布。因此(在许多其他更正中),最终代码是:

feed = '<?xml version="1.0" encoding="utf-8"?><AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Header>'
feed += '<DocumentVersion>1.01</DocumentVersion><MerchantIdentifier>A3RVNLI4ZWO9K4</MerchantIdentifier></Header><MessageType>Price</MessageType><Message><MessageID>1</MessageID>'
feed += '<Price><SKU>sa400240g</SKU><MaximumSellerAllowedPrice currency="EUR">975</MaximumSellerAllowedPrice></Price></Message></AmazonEnvelope>'

encodedFeed = feed.encode('utf-8')
md5 = hashlib.md5(encodedFeed)
encodedMd5 = base64.b64encode(md5.digest())
parsedMd5 = urllib.parse.quote(encodedMd5, safe='')

request_string = construct_strings(seller, '', 'SubmitFeed', '2009-01-01', args_dict)
myHeader = {'Content-MD5': encodedMd5.decode('utf-8'), 'Content-Type': 'text/xml'}
response = requests.post(request_string, headers = myHeader, data = feed)

谢谢,无论如何!希望这个解决方案可以帮助遇到同样问题的人!

关于python - 错误 "the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60438069/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com