|
21 | 21 | from requests.exceptions import HTTPError |
22 | 22 |
|
23 | 23 |
|
| 24 | +__all__ = [ |
| 25 | + 'AmazonTextResponse', |
| 26 | + 'AmazonXMLResponse', |
| 27 | + 'Feeds', |
| 28 | + 'Inventory', |
| 29 | + 'Reports', |
| 30 | + 'Orders', |
| 31 | + 'Products', |
| 32 | + 'Recommendations', |
| 33 | + 'Sellers', |
| 34 | +] |
| 35 | + |
| 36 | +# See https://images-na.ssl-images-amazon.com/images/G/01/mwsportal/doc/en_US/bde/MWSDeveloperGuide._V357736853_.pdf page 8 |
| 37 | +# for a list of the end points and marketplace IDs |
| 38 | + |
| 39 | +MARKETPLACES = { |
| 40 | + "CA" : "https://mws.amazonservices.ca", #A2EUQ1WTGCTBG2 |
| 41 | + "US" : "https://mws.amazonservices.com", #ATVPDKIKX0DER", |
| 42 | + "DE" : "https://mws-eu.amazonservices.com", #A1PA6795UKMFR9 |
| 43 | + "ES" : "https://mws-eu.amazonservices.com", #A1RKKUPIHCS9HS |
| 44 | + "FR" : "https://mws-eu.amazonservices.com", #A13V1IB3VIYZZH |
| 45 | + "IN" : "https://mws.amazonservices.in", #A21TJRUUN4KGV |
| 46 | + "IT" : "https://mws-eu.amazonservices.com", #APJ6JRA9NG5V4 |
| 47 | + "UK" : "https://mws-eu.amazonservices.com", #A1F83G8C2ARO7P |
| 48 | + "JP" : "https://mws.amazonservices.jp", #A1VC38T7YXB528 |
| 49 | + "CN" : "https://mws.amazonservices.com.cn", #AAHKV2X7AFYLW |
| 50 | +} |
| 51 | + |
24 | 52 |
|
25 | 53 | class MWSError(Exception): |
26 | 54 | """ |
@@ -114,40 +142,23 @@ class MWS(object): |
114 | 142 | # Which is the name of the parameter for that specific account type. |
115 | 143 | ACCOUNT_TYPE = "SellerId" |
116 | 144 |
|
117 | | - def __init__(self, access_key, secret_key, account_id, region = 'US', |
118 | | - domain='', uri="", version=""): |
| 145 | + def __init__(self, access_key, secret_key, account_id, region='US', domain='', uri="", version=""): |
119 | 146 | self.access_key = access_key |
120 | 147 | self.secret_key = secret_key |
121 | 148 | self.account_id = account_id |
122 | 149 | self.version = version or self.VERSION |
123 | | - self.region = region |
124 | | - # Get the domain for the default of passed region, or use the passed domain |
125 | | - self.domain = domain or self.get_region_endpoint() |
126 | 150 | self.uri = uri or self.URI |
127 | | - |
128 | | - def get_region_endpoint(self): |
129 | | - # See https://images-na.ssl-images-amazon.com/images/G/01/mwsportal/doc/en_US/bde/MWSDeveloperGuide._V357736853_.pdf page 8 |
130 | | - # for a list of the end points and marketplace IDs |
131 | | - try: |
132 | | - marketplaces = { |
133 | | - "CA" : "https://mws.amazonservices.ca", #A2EUQ1WTGCTBG2 |
134 | | - "US" : "https://mws.amazonservices.com", #ATVPDKIKX0DER", |
135 | | - "DE" : "https://mws-eu.amazonservices.com", #A1PA6795UKMFR9 |
136 | | - "ES" : "https://mws-eu.amazonservices.com", #A1RKKUPIHCS9HS |
137 | | - "FR" : "https://mws-eu.amazonservices.com", #A13V1IB3VIYZZH |
138 | | - "IN" : "https://mws.amazonservices.in", #A21TJRUUN4KGV |
139 | | - "IT" : "https://mws-eu.amazonservices.com", #APJ6JRA9NG5V4 |
140 | | - "UK" : "https://mws-eu.amazonservices.com", #A1F83G8C2ARO7P |
141 | | - "JP" : "https://mws.amazonservices.jp", #A1VC38T7YXB528 |
142 | | - "CN" : "https://mws.amazonservices.com.cn", #AAHKV2X7AFYLW |
| 151 | + |
| 152 | + if domain: |
| 153 | + self.domain = domain |
| 154 | + elif region in MARKETPLACES: |
| 155 | + self.domain = MARKETPLACES[region] |
| 156 | + else: |
| 157 | + error_msg = "Incorrect region supplied ('%(region)s'). Must be one of the following: %(marketplaces)s" % { |
| 158 | + "marketplaces" : ', '.join(MARKETPLACES.keys()), |
| 159 | + "region" : region, |
143 | 160 | } |
144 | | - return marketplaces[self.region.upper()] |
145 | | - # Didn't pass a valid marketplace location. |
146 | | - except KeyError: |
147 | | - raise MWSError("Incorrect region supplied ('%(region)s'). Must be one of the following: %(marketplaces)s" % { |
148 | | - "marketplaces" : marketplaces.keys(), |
149 | | - "region" : self.region, |
150 | | - }) |
| 161 | + raise MWSError(error_msg) |
151 | 162 |
|
152 | 163 | def make_request(self, extra_data, method="GET", **kwargs): |
153 | 164 | """Make request to Amazon MWS API with these parameters |
|
0 commit comments