lionheart / bottlenose

A Python wrapper for the Amazon Product Advertising API.
Apache License 2.0
577 stars 112 forks source link

Http 403 error bottlenose python (Amazon API) #51

Closed chaitra-kamath closed 7 years ago

chaitra-kamath commented 8 years ago

I am trying to access data using Amazon's API. I created product advertisement and aws account with same email and password, got the aws_secret, aws_key and affiliate_associate_key.

Then, I tried the following:

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')

And, I get the HTTP 403 error as follows (I added some print statement in my urllib2.py file):

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

Things tried:

I made sure that all the keys and the associate_tag are infact from the same account. I also synced clock on my machine (which was in Central timezone) to sync to N.California timezone. I have made around 5 requests in over an hour.

I am using Python v 2.7.11 and running this code using Anaconda's QtConsole on my machine locally.

Appreciate any help!

XianwuLin commented 7 years ago

same issue

dlo commented 7 years ago

I've created a "bottlenose" tag on Stack Overflow and encourage anyone running into usage-related questions there instead of here on the issue tracker. Please only open a new issue if you find a bug or have a feature request. Thanks! ✨