Amazon Europe MWS Python Boto Connection AccessDen

2019-07-18 14:58发布

Recently, I started learning Python. I plan to build a program for our company to manage the orders from all the Amazon Marketplace websites, our own Bigcommerce store and eBay.

Now I can use the Boto library to successfully send requests to Amazon US, Amazon Canada, and Amazon Mexico and get all the order information. (Boto is the only library I could find that works perfect with Amazon MWS) But when I use the same method to send requests to Amazon.co.uk, it failed. Here is the sample code I used to send the requests.

from boto.mws.connection import MWSConnection
MarketPlaceID = marketplaceid
MerchantID = merchantid
AccessKeyID = accesskeyid
SecretKey = secretkey
mws = MWSConnection(AccessKeyID,SecretKey)
mws.SellerId = MerchantID
mws.Merchant = MerchantID
mws.MarketplaceId = MarketPlaceID
orderstatus = ['PartiallyShipped','Unshipped', 'Shipped']
orders=mws.list_orders(LastUpdatedAfter = '2016-05-01T17:00:00Z', MarketplaceId = [MarketPlaceID],OrderStatus=orderstatus)

This code works very good for our stores on Amazon Canada, Amazon US and Amazon Mexico. But when I use it for Amazon.co.uk., I alaways get these AccessDenied codes. (I 100% confirm that all the marketplaceid, sellersid, accesskeyid and secretkeyid are correct.)

AccessDenied
Traceback (most recent call last):
  File "C:\Python\Amazon Test.py", line 17, in <module>
orders=mws.list_orders(LastUpdatedAfter='2016-05-01T17:00:00Z', MarketplaceId = [MarketPlaceID],OrderStatus=orderstatus)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 158, in requires
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 158, in requires
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 177, in wrapper
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 196, in wrapper
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 177, in wrapper
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 196, in wrapper
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 177, in wrapper
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 139, in wrapper
return func(*args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 81, in wrapper
return func(self, *args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 252, in wrapper
return func(self, request, response, *args, **kw)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 732, in list_orders
return self._post_request(request, kw, response)
  File "C:\Users\Yinghao\AppData\Local\Programs\Python\Python35-32\lib\site-packages\boto\mws\connection.py", line 323, in _post_request
response.reason, body)
boto.mws.response.ResponseFactory.element_factory.<locals>.DynamicElement:         AccessDenied: Unauthorized 
Access denied

Could anyone please tell me how to make the requests to connect to Amazon.co.uk via Python Boto library or other Python libraries? Any help will be significantly appreciated.

Thanks

1条回答
再贱就再见
2楼-- · 2019-07-18 15:45

I figured it out myself. The key is the code of this line, https://github.com/boto/boto/blob/develop/boto/mws/connection.py#L269

After changing 'mws.amazonservices.com' to 'mws-eu.amazonservices.com', I can use the code above to connect to Amazon Europe. So this issue is all about the Amazon Amazon MWS endpoints. I can use Boto to connect to Amazon Japan, China, India, Europe by following the instruction of this page, http://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html

查看更多
登录 后发表回答