使用Python3 Amazon API时遇到问题。我注意到很多人都遇到同样的问题,但是我到处都在寻找解决方案,但没有结果。
我正在尝试这段简单的代码:
from amazon.api import AmazonAPI
amazon = AmazonAPI (my_AMAZON_ACCESS_KEY, my_AMAZON_SECRET_KEY, my_AMAZON_ASSOC_TAG, region=’IT’)
products = amazon.search(Keywords = "book name", SearchIndex = "Books")
print(products)
#<amazon.api.AmazonSearch object at 0x7fcc238e7a20>
直到这里起作用。
for item in products:
print (item.title, item.isbn, item.price_and_currency)
在这里出现以下错误:
File "amazon_loader.py", line 78, in getItemFromAmazon
for item in products:
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/site-packages/amazon/api.py", line 544, in __iter__
for page in self.iterate_pages():
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/site-packages/amazon/api.py", line 561, in iterate_pages
yield self._query(ItemPage=self.current_page, **self.kwargs)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/site-packages/amazon/api.py", line 573, in _query
response = self.api.ItemSearch(ResponseGroup=ResponseGroup, **kwargs)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/site-packages/bottlenose/api.py", line 274, in __call__
{'api_url': api_url, 'cache_url': cache_url})
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/site-packages/bottlenose/api.py", line 235, in _call_api
return urllib2.urlopen(api_request, timeout=self.Timeout)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/home/valentinim/.conda/envs/telepot/lib/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
我想这是python urrlib库的问题,而不是AmazonAPI的问题。此外,我认为尝试从下载的AmazonSearch对象中请求信息时与身份有关,但是我不知道如何解决该问题。
我也尝试了Python2,没有区别。