如何在python 3中修复Amazon api请求的“ HTTP错误400:错误的请求”?

时间:2019-04-26 16:21:14

标签: python python-3.x amazon-product-api

我是一名Python初学者,正在尝试使用Python 3.x和Anaconda发出Amazon-Api-Request并获得此响应。我花了很多时间试图解决此问题,但邓恩特想出了一个解决方案。 强文本

输入:

from amazon.api import AmazonAPI

AMAZON_ACCESS_KEY = "..."
AMAZON_SECRET_KEY = "..."
AMAZON_ASSOC_TAG = "..."

amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG)

products = amazon.search(Keywords="knoblauchpresse", SearchIndex='All')
for i, product in enumerate(products):
    print(product.title, product.list_price, product.asin)

输出:

HTTPError                                 Traceback (most recent call last)
<ipython-input-39-84eb43d7eab0> in <module>
      8 
      9 products = amazon.search(Keywords="knoblauchpresse", SearchIndex='All')
---> 10 for i, product in enumerate(products):
     11     print(product.title, product.list_price, product.asin)

/anaconda3/lib/python3.7/site-packages/amazon/api.py in __iter__(self)
    542             Yields a :class:`~.AmazonProduct` for each result item.
    543         """
--> 544         for page in self.iterate_pages():
    545             for item in getattr(page.Items, 'Item', []):
    546                 yield AmazonProduct(

/anaconda3/lib/python3.7/site-packages/amazon/api.py in iterate_pages(self)
    559             while not self.is_last_page:
    560                 self.current_page += 1
--> 561                 yield self._query(ItemPage=self.current_page, **self.kwargs)
    562         except NoMorePages:
    563             pass

...

/anaconda3/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 400: Bad Request

0 个答案:

没有答案