I am trying to set a maximum price for a product using Amazon API in a Django (Python) environment. I already solved the problem with calculating the md5 function which value is exactly the same as Amazon MWS Scratchpad calculates.
After solving this issue, I get now a "the Content-MD5 HTTP header you passed for your feed did not match the Content-MD5 we calculated for your feed" error message.
My code is as follows:
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()
It's my first question asked here in stackOverflow. I appreciate any hints you can give me.
Thanks!