item_lookup with multiple ItemId's

rkatcher avatarrkatcher created an issue

Hi, I've been using this API for a few days now and love it, thanks for the great work!

I recently encountered behavior that may be an issue and hoping someone here may know ...

I am doing ItemLookup with multiple ItemId's, but if any of the ItemId's are not found on the Amazon site than the whole request fails. I should mention that I added an IdType parameter to item_lookup so I could lookup an item with UPC (pretty straightforward). prodResult = api.item_lookup(UPCstr, IdType='UPC', SearchIndex=searchIndex, ResponseGroup='Offers,ItemAttributes')

So if I send it the following UPC's (644209004461, 009800895250, 024100440771) everything works fine and prodResult is set. But if I add 301357583001 to the list than the entire item_lookup fails and prodResult is never set. Is this expected? I would think it would return an error for that Item but return results for the rest. I can do the item_lookup's individually but that makes it way too slow when you have anything but a small number of items (sometimes I need to lookup a 15-20 items at a time).

For the record, this has nothing to do with locale as a lot of others have experienced with the InvalidParameterValue error (my locale is 'us' fwiw). That is the error I would expect per Amazon's documentation for this lookup (UPC not found on ItemLookup) http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html

But again my question is whether the entire item_lookup call should fail with InvalidParameterValue when 1 of n ItemId's are invalid.

Thanks for any info you can provide.

Rob

Comments (18)

  1. Sebastian Rahlf
    • changed status to open

    I quite agree with you. One bad itemId should not make the whole operation fail. The problem here, however, is that Amazon's XML response will contain an error message which this module picks up and throws the appropriate Python exception. It would be interesting to see if the rest of the XML contained item information.

    Presumeably you are getting a amazonproduct.errors.InvalidParameterValue exception. If not please provide traceback and API version.

  2. Sebastian Rahlf

    From the looks of it there is information about the items inside the returned XML. Hmmm.

    The question is how would you make this information available and raise the exception at the same time? Maybe something like

    try:
        prodResult = api.item_lookup(UPCstr, IdType='UPC')
    except InvalidParameterValue, e:
        print "There was an invalid ItemId!"
        prodResult = e.xml
    
  3. rkatcher

    Thanks Sebastian. That's great news that Amazon is returning more xml that might be useful.

    Unless I'm mistaken though, e does not contain xml at that point. e seems to only contain the UPC that was not found along with the ItemId identifier. ('ItemId', '301357583001')

    So the question is really how do I get at the results from Amazon? Please pardon me if this is an elementary question, as I am still coming up to speed on python. Thanks.

    Rob

  4. Sebastian Rahlf

    Well, at the moment this is just a figment of my imagination. Let's see what I can do about this in the next release.

    Keep nagging me, if you don't see this feature in version 0.2.6!

  5. rkatcher

    OK, thanks again Sebastian. I'm sure you realize it, but this issue is pretty important for performance reasons ... at roughly a second per Amazon call, doing individual lookups on 15-20 UPC's is too long for an end user to wait. I can prefetch some of it, but Amazon changes their offers pretty frequently so I can't cache offers for very long. I will take a look at the code as well, but will likely need a more experienced developer to figure it out.

    Rob

  6. rkatcher

    Sebastian, so it turns out Amazon is returning valid results for all the other lookups like you suspected. I am working around this for now ... I simply modified the call function to not raise the InvalidParameter exception ... probably not a good long term solution :), but it works for my purposes for now ... perhaps longer term it could attach the error to the results and let the caller check for it and determine how to handle that Amazon error code based on the situation since Amazon seems to apply it very liberally. Hope that is helpful to you when you get around to this down the road. Thanks again for the great API!!

  7. jageb

    Hey Sebastian,

    this seems to no longer work.

    I query the api with EANs. If one EAN is not found, "e" from your example returns only: ('ItemId', '#replace_with_bad_item_id').

    Is this working as expected and the example is just outdated?

  8. jageb

    api = API(AWS_KEY, SECRET_KEY, 'de',ASSOCIATE_TAG)

    params = {
        'ResponseGroup' : 'Large',
        'SearchIndex' : 'All',
        'IdType' : 'EAN',
        }
    
    try:
        root = api.item_lookup('5051890006479', '886976038892', '4010884258875', **params)
    except InvalidParameterValue,e:
    
        print "e is",e
        root = e.xml
    
    print type(root)
    

    output is: e is ('ItemId', '886976038892') <type 'NoneType'>

  9. jageb

    Im still struggling with this one on 0.2.7.

    cfg = {"access_key":"", "secret_key":"","associate_tag":""}
    api = API(locale="de", cfg=cfg)
    params = {"ResponseGroup": "Large", "IdType":"ASIN"}
    keywords = ["B00CX7C0FQ", "B00F8ZEAX0"]
    try:
        result = api.item_lookup(*keywords, **params)
    except InvalidParameterValue, e:
        result = e
    
    result
    >>> InvalidParameterValue('ItemId', 'B00CX7C0FQ')
    result.__class__
    >>> <class 'amazonproduct.errors.InvalidParameterValue'>
    result.__dict__
    >>> {'msg': None, 'xml': None, 'code': None}
    
  10. jageb

    Nice. I just forked the repo and made a fix for this (needed to pass the xml on reraise), but #42 seems to be a more general approach, so I'll wait for your release.

    Do you have a ETA on when you will push this to the dev branch?

  11. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.