1. Sebastian Rahlf
  2. python-amazon-product-api
  3. Issues
Issue #25 resolved

api suddenly not working! LxmlItemSearchPaginator

Anonymous created an issue


Let me thanks for the awesome API wrapper first. I've been using this package for more than one months and have not problem. However, I got the following error today: 'LxmlItemSearchPaginator' object has no attribute 'Items'

Since I already set up everything and work fine, I suspect the error is co-related to changes from amazon side (although I cannot find any particular useful info from amazon's site). If you google the message line, you will only find error report from this few days. Can anyone confirm this? And hopefully fix this? Thanks.

ps: my code is extremly similar to the demo code like this:

AWS_KEY = '...'
SECRET_KEY = '...'

api = API(AWS_KEY, SECRET_KEY, 'de')
node = api.item_search('Books', Publisher='Galileo Press')

The node object returned is a lxml.objectified_ element. All its attributes can be accessed the pythonic way::

total_results = node.Items.TotalResults.pyval
total_pages = node.Items.TotalPages.pyval

# get all books from result set and 
# print author and title
for book in node.Items.Item:
    print '%s: "%s"' % (book.ItemAttributes.Author, 

Comments (7)

  1. Anonymous
    Request Method: GET
    Request URL:
    Django Version: 1.3
    Python Version: 2.6.6
    Installed Applications:
    Installed Middleware:
    File "/home/test/test/venv/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
      111.                         response = callback(request, *callback_args, **callback_kwargs)
    File "/home/test/test/app/test/views.py" in test
      328.     (products,resultNum) = affiliateAPIObj.searchKeywords("linux",1,searchIndex="All")
    File "/home/test/test/app/test/affiliateAPI.py" in searchKeywords
      21.       (products,resultNum) = self.amazon.searchKeywords(keywords,itemPage,**kwargs)
    File "/home/test/test/app/test/amazon.py" in searchKeywords
      121.         return self._extractAmazonInfo(root)
    File "/home/test/test/neurodiffuse/app/test/amazon.py" in _extractAmazonInfo
      84.         for product in root.Items.Item:
    Exception Type: AttributeError at /test/
    Exception Value: 'LxmlItemSearchPaginator' object has no attribute 'Items'

    Feel free to tell me what info you need. Thanks again.

  2. Anonymous

    Ok, I re-confirm this issue by running the following code:

        params = { 'ResponseGroup' : 'Medium', }
        api = AmazonAPI(AWS_KEY, SECRET_KEY, 'us')
        root = api.item_search("All", Keywords="linux", ItemPage=1, **params)
        for product in root.Items.Item:

    Here is what I got:

    Traceback (most recent call last):
      File "amazon.py", line 133, in <module>
        for product in root.Items.Item:
    AttributeError: 'LxmlItemSearchPaginator' object has no attribute 'Items'
  3. Sebastian Rahlf repo owner

    What you are describing is very likely not a problem but really a feature (TM).

    ItemSearch will give you your results in chunks of 10 per page. With 036ffcc22f7d I've introduced automatic pagination which will, when iterated over, fetch all subsequent pages.

    If you change your code to this

    for page in api.item_search("All", Keywords="linux", **params)
        for product in page.Items.Item:
            print product

    it should work again.

    For my use case this make perfect sense. However, I'm always grateful for some feedback/suggestions or even the odd pull request.

  4. Log in to comment