0
我想使用亞馬遜的API訪問數據。我使用相同的電子郵件和密碼創建了產品廣告和aws帳戶,獲得了aws_secret,aws_key和affiliate_associate_key。HTTP 403錯誤瓶鼻Python(亞馬遜API)
然後,我試過如下:
import bottlenose
aws_key = 'my_aws_key'
aws_secret = 'my_aws_secret'
aws_associate_tag = 'my_aws_associate_tag'
amazon = bottlenose.Amazon(aws_key, aws_secret, aws_associate_tag)
product = amazon.lookup(ItemId='B00EOE0WKQ')
而且,我得到的HTTP 403錯誤如下(我加在我的urllib2.py文件中的一些打印語句):
message from urllib2.py Forbidden
headers from urllib2.py Date: Sun, 21 Aug 2016 05:44:59 GMT
Server: Apache-Coyote/1.1
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 304
Keep-Alive: timeout=2, max=15
Connection: Keep-Alive
code from urllib2.py 403
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-1-973306797553> in <module>()
5
6 amazon = bottlenose.Amazon(aws_key, aws_secret, aws_associate_tag)
----> 7 product = amazon.lookup(ItemId='B00EOE0WKQ')
8
/Users/chaitra/anaconda/lib/python2.7/site-packages/bottlenose/api.pyc in __call__(self, **kwargs)
263 # make the actual API call
264 response = self._call_api(api_url,
--> 265 {'api_url': api_url, 'cache_url': cache_url})
266
267 # decompress the response if need be
/Users/chaitra/anaconda/lib/python2.7/site-packages/bottlenose/api.pyc in _call_api(self, api_url, err_env)
224 else:
225 # the simple way
--> 226 return urllib2.urlopen(api_request, timeout=self.Timeout)
227 except:
228 if not self.ErrorHandler:
/Users/chaitra/anaconda/lib/python2.7/urllib2.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
152 else:
153 opener = _opener
--> 154 return opener.open(url, data, timeout)
155
156 def install_opener(opener):
/Users/chaitra/anaconda/lib/python2.7/urllib2.py in open(self, fullurl, data, timeout)
438 for processor in self.process_response.get(protocol, []):
439 meth = getattr(processor, meth_name)
--> 440 response = meth(req, response)
441
442 return response
/Users/chaitra/anaconda/lib/python2.7/urllib2.py in http_response(self, request, response)
551 if not (200 <= code < 300):
552 response = self.parent.error(
--> 553 'http', request, response, code, msg, hdrs)
554
555 return response
/Users/chaitra/anaconda/lib/python2.7/urllib2.py in error(self, proto, *args)
476 if http_err:
477 args = (dict, 'default', 'http_error_default') + orig_args
--> 478 return self._call_chain(*args)
479
480 # XXX probably also want an abstract factory that knows when it makes
/Users/chaitra/anaconda/lib/python2.7/urllib2.py in _call_chain(self, chain, kind, meth_name, *args)
410 func = getattr(handler, meth_name)
411
--> 412 result = func(*args)
413 if result is not None:
414 return result
/Users/chaitra/anaconda/lib/python2.7/urllib2.py in http_error_default(self, req, fp, code, msg, hdrs)
559 class HTTPDefaultErrorHandler(BaseHandler):
560 def http_error_default(self, req, fp, code, msg, hdrs):
--> 561 raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
562
563 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden
嘗試過的東西:
- 我確保所有的鍵和associate_tag從infact同一個帳戶。
- 我還在我的機器上同步時鐘(中央時區)以同步到N.California時區。
- 我在一個多小時內提出了5個請求。
我正在使用Python v 2.7.11並在本地機器上使用Anaconda的QtConsole運行此代碼。