Issue #41 resolved

URLError on item_search

A Jagoe
created an issue

I used your code sample solution to issue #25 and it works fine to get the data. However, after returning the data, my script never completes...and finally the below error is returned from the api. The blocker for me is I cannot process the data once I get it because the script hangs.

Any ideas?

Traceback (most recent call last):
  File "fbNote.py", line 61, in <module>
    result = aws_product_search(line.strip())
  File "fbNote.py", line 27, in aws_product_search
    for page in api.item_search("All", Keywords=keywords):
  File "/Library/Python/2.7/site-packages/amazonproduct/paginators.py", line 47, in __iter__
    yield self.page(self.current + 1) 
  File "/Library/Python/2.7/site-packages/amazonproduct/paginators.py", line 54, in page
    root = self.fun(*self.args, **self.kwargs)
  File "/Library/Python/2.7/site-packages/amazonproduct/paginators.py", line 75, in <lambda>
    method = lambda *a, **b: fnc(api, *a, **b)
  File "/Library/Python/2.7/site-packages/amazonproduct/api.py", line 360, in item_search
    SearchIndex=search_index, **params)
  File "/Library/Python/2.7/site-packages/amazonproduct/api.py", line 281, in call
    fp = self._fetch(url)
  File "/Library/Python/2.7/site-packages/amazonproduct/api.py", line 208, in _fetch
    response = opener.open(request)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 394, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 412, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1199, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1174, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error timed out>

Comments (4)

  1. Sebastian Rahlf repo owner

    This may be a temporary network problem. Try this

    from amazonproduct import API
    
    import logging
    logger = logging.getLogger('amazonproduct.api')
    logging.basicConfig(level=logging.DEBUG)
    
    class LoggingAPI (API):
    
        def call(self, **qargs):
            logger.info('Calling API with %r' % qargs)
            return super(LoggingAPI, self).call(**qargs)
    
        def _fetch(self, url):
            logger.debug('Fetching %s...' % url)
            return super(LoggingAPI, self)._fetch(url)
    

    and simply use LoggingAPI instead of API in your code. This should give you a bit more insight.

  2. A Jagoe reporter

    Thanks for the quick response Sebastian. There seems to be an issue with the iterator over the LxmlItemSearchPaginator object returned from my code.

    for page in api.item_search("All", Keywords=keywords):
        for product in page.Items.Item:
            print product.ItemAttributes.Title
    

    I'm looping through a file where each line has the keywords for a specific search. All the data is returned fine, but the loop over the file hangs when it should complete. If I remove the code I pasted above for the LxmlItemSearchPaginator iterator, the file loop returns just fine.

    Below is the console output of the last item in the file. Exactly as desired...except for the problem with the iterator. I'm using Python 2.7.2 on OS X 10.8.2.

    Sorry for the messy display...I can't seem to get the bitbucket markdown to work correctly for it...

    Timbuk2 Classic Messenger Bag INFO:amazonproduct.api:Calling API with {'Keywords': 'Timbuk2+Classic+Messenger+Bag', 'ItemPage': 1, 'Operation': 'ItemSearch', 'SearchIndex': 'All', 'limit': 5} DEBUG:amazonproduct.api:Fetching http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJJAOFFDAY4L6RA5Q&AssociateTag=venturegrit-20&ItemPage=1&Keywords=Timbuk2%2BClassic%2BMessenger%2BBag&Operation=ItemSearch&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-14T17%3A53%3A45Z&Version=2010-12-01&limit=5&Signature=VteXtn2fajhYV4lAPNY1OAkQcMWfGV5JIzDjo1JK0Tk%3D... Timbuk2 Command Laptop Messenger Bag (Black, Medium) INFO:amazonproduct.api:Calling API with {'ItemId': 'B005HEV52G', 'Operation': 'ItemLookup', 'ResponseGroup': 'Images,Small'} DEBUG:amazonproduct.api:Fetching http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJJAOFFDAY4L6RA5Q&AssociateTag=venturegrit-20&ItemId=B005HEV52G&Operation=ItemLookup&ResponseGroup=Images%2CSmall&Service=AWSECommerceService&Timestamp=2012-12-14T17%3A53%3A46Z&Version=2010-12-01&Signature=0aVrNiiERb2sYx61r2VIfja7wFKxkiVL%2Bs8h1y7Q90s%3D... INFO:amazonproduct.api:Calling API with {'Keywords': 'Timbuk2+Classic+Messenger+Bag', 'ItemPage': 2, 'Operation': 'ItemSearch', 'SearchIndex': 'All', 'limit': 5} DEBUG:amazonproduct.api:Fetching http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJJAOFFDAY4L6RA5Q&AssociateTag=venturegrit-20&ItemPage=2&Keywords=Timbuk2%2BClassic%2BMessenger%2BBag&Operation=ItemSearch&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-14T17%3A53%3A46Z&Version=2010-12-01&limit=5&Signature=RzPprz5xZMPoHtW5Bm%2BpRR90XXn6Vmgm2TPI5KjS17U%3D... INFO:amazonproduct.api:Calling API with {'Keywords': 'Timbuk2+Classic+Messenger+Bag', 'ItemPage': 3, 'Operation': 'ItemSearch', 'SearchIndex': 'All', 'limit': 5} DEBUG:amazonproduct.api:Fetching http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJJAOFFDAY4L6RA5Q&AssociateTag=venturegrit-20&ItemPage=3&Keywords=Timbuk2%2BClassic%2BMessenger%2BBag&Operation=ItemSearch&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-14T17%3A53%3A48Z&Version=2010-12-01&limit=5&Signature=UDow8K4p1V1qKcSviNhfen7pN99O9cPIiyoXPYllTCU%3D... INFO:amazonproduct.api:Calling API with {'Keywords': 'Timbuk2+Classic+Messenger+Bag', 'ItemPage': 4, 'Operation': 'ItemSearch', 'SearchIndex': 'All', 'limit': 5} DEBUG:amazonproduct.api:Fetching http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJJAOFFDAY4L6RA5Q&AssociateTag=venturegrit-20&ItemPage=4&Keywords=Timbuk2%2BClassic%2BMessenger%2BBag&Operation=ItemSearch&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-14T17%3A53%3A49Z&Version=2010-12-01&limit=5&Signature=h6BL7aTm9dOhHHECl2jJfzPrFJfCQTDHU6pbc0XA8KQ%3D... INFO:amazonproduct.api:Calling API with {'Keywords': 'Timbuk2+Classic+Messenger+Bag', 'ItemPage': 5, 'Operation': 'ItemSearch', 'SearchIndex': 'All', 'limit': 5} DEBUG:amazonproduct.api:Fetching http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJJAOFFDAY4L6RA5Q&AssociateTag=venturegrit-20&ItemPage=5&Keywords=Timbuk2%2BClassic%2BMessenger%2BBag&Operation=ItemSearch&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-14T17%3A53%3A50Z&Version=2010-12-01&limit=5&Signature=Z3ckys1td610/1yMql6nDo3ZxiPq9Pq1eY%2B/0SpNvfk%3D... Finished

  3. Log in to comment