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

11/1/2011 new requirement AssociateTag -- update required?

robcohen
created an issue

API requirements changed effective 1 November 2011; AssociateTag is now a required parameter

Either the wrapper needs an update to support the parameter or I need to be educated on what parameter to use in the wrapper to pass AssociateTag. Genuine Python newbie here!

Thanks, Rob

Comments (10)

  1. Sebastian Rahlf repo owner
    • changed status to open

    Update is in the making (see #27). In the meantime, you can pass your associate tag as follows:

    api = amazonproduct.API(AWS_KEY, SECRET_KEY, locale='us', AssociateTag='...')
    

    Let me know if this solves your problems.

  2. robcohen reporter

    (Reply via r...@sfcomputech.com):

    Sebastian, Thanks for your response - just noticed I hadn't responded. Workaround does it for me, just set a variable AssociateTag to the right value and append it in the call to the API.

    Having other issues though that are making the look-ups all fail anyway so no joy here in Mudville: AttributeError: 'LxmlItemSearchPaginator' object has no attribute 'Items'

    Ah, just saw issue 25 and it looks like there may be a way around this. Right now my (borrowed) code is:

    import sys from amazonproduct import API

    AWS_KEY = 'A...Q' SECRET_KEY = '..' AssociateTag='me-20' api = API(AWS_KEY, SECRET_KEY, "us", AssociateTag) node = api.item_search('KindleStore', Title=sys.argv[1], Author=sys.argv[2])

    for book in node.Items.Item: print '%s' % (book.ASIN)

    If it's an easy thing to tell me what to change to fix this, can you? I'm not at all familiar with Python. I have read over the wrapper documentation as well as Issue 25 hoping for enlightenment. I don't even see item_search defined as as an operation for the API. The idea is to find the ASIN if title and author match. Title and Author are passed when this code is called (from a windows batch program). Is the item_search function still supported or is there a better way to do this?

    Based on what I saw in your response to #25, I started to rewrite the last part of the Python code but I'm stuck. Sorry to grovel :-).

    Thanks! Rob

    • Rob Cohen S F Computech Small Business IT Support Specialist tel.415.244.3305*
  3. robcohen reporter

    Sebastian, Looks like I continued to piddle with the code after I wrote you and now I'm only getting a syntax error at execution. Probably a simple noob mistake but I don't know enough Python to get out of it.

    Get the same result if I code it exactly as your previous post showed with: for page in api.item_search('KindleStore', sys.argv[1], sys.argv[2], AssociateTag='...value')

    Thanks! Rob

    C:\Users\Robert\Calibre Library>scr5 Number of files: 1016 File "asin_search1.py", line 10 for page in api.item_search('KindleStore', sys.argv[1], sys.argv[2], Associa teTag)

    ^ SyntaxError: invalid syntax Gave a fake ASIN number to: Cutting for Stone. It's new number is B001258170 fcount = 1 Terminate batch job (Y/N)?

    Code is:

    import sys
    from amazonproduct import API
    
    AWS_KEY = 'AKIAJY3JK65CNSQDYSVQ'
    SECRET_KEY = 'o............................g'
    AssociateTag='wwwsfcomputec-20'
    
    api = API(AWS_KEY, SECRET_KEY, "us", AssociateTag='wwwsfcomputec-20')
    
    for page in api.item_search('KindleStore', sys.argv[1], sys.argv[2])
    	for product in page.Items.Item
    	print '%s' % (book.ASIN)
    
  4. robcohen reporter

    Sebastian, Thanks, I look forward to working through the book.

    I added the colons and indentation and now get a TypeError: item_search() takes exactly 2 arguments (5 given)

    <pre>import sys from amazonproduct import API

    AWS_KEY = 'A...Q' SECRET_KEY = '...' ASSOCIATE_TAG='wwwsfcomputec-20'

    api = API(AWS_KEY, SECRET_KEY, "us", ASSOCIATE_TAG)

    for page in api.item_search('KindleStore', sys.argv[1], sys.argv[2]): for product in page.Items.Item: print '%s' % (book.ASIN) </pre>

    Output looks like this (calling the Python code from a .bat script):

    C:\Users\Robert\Calibre Library>scr5 Number of files: 1016 Traceback (most recent call last): File "asin_search1.py", line 10, in <module> for page in api.item_search('KindleStore', sys.argv[1], sys.argv[2]): File "build\bdist.win32\egg\amazonproduct\paginators.py", line 76, in wrapped File "build\bdist.win32\egg\amazonproduct\paginators.py", line 134, in init_ _ File "build\bdist.win32\egg\amazonproduct\paginators.py", line 96, in init__

    File "build\bdist.win32\egg\amazonproduct\paginators.py", line 38, in init

    File "build\bdist.win32\egg\amazonproduct\paginators.py", line 54, in page File "build\bdist.win32\egg\amazonproduct\paginators.py", line 75, in <lambda>

    TypeError: item_search() takes exactly 2 arguments (5 given) Gave a fake ASIN number to: Cutting for Stone. Its new number is B007343153 fcount = 1 rcount = 0 fcount = 1

    Not sure why it sees five arguments. Tried changing the call to item_search in a couple of different ways to try to get a handle why it sees 5 arguments and am way over my head, at least until I spend some serious time with the book you recommend. If I take out the first parameter, 'KindleStore' and just pass Title and Author it always sees 4 arguments. Thought maybe it have something to do with the contents of the Title and Author but it always sees the same number of arguments.

    At least my syntax is not the issue any more :-). Any ideas? The batch script that passes title and author are completely by someone else and well beyond my comprehension without analyzing it line by line to see if it's actually broken somehow.

    Thanks! Rob

  5. Sebastian Rahlf repo owner

    In short, you need to use keyword arguments. In your case that would be something like

    api.item_search('KindleStore', Title=sys.argv[1], Publisher=sys.argv[2])
    

    You can find the exact parameters to use in the Amazon documentation http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/DG/index.html?CHAP_OperationListAlphabetical.html

    I will close this issue here. If you have more questions regarding this, please post to the mailing list https://groups.google.com/group/python-amazon-product-api-devel

  6. robcohen reporter

    Sebastian, Thanks again for your help on this. Have got the Python code working now.

    import sys
    from amazonproduct import API
    
    AWS_KEY = '...............................'
    SECRET_KEY = '....................................................'
    ASSOCIATE_TAG='..................'
    
    api	 = API(AWS_KEY, SECRET_KEY, "us", ASSOCIATE_TAG)
    
    for book in api.item_search('KindleStore', Title=sys.argv[1], Author=sys.argv[2]):
    	for book in book.Items.Item:
    		print '%s' % (book.ASIN)
    

    And now I have a great 'spare time' book to read to learn more about Python, thanks to you.

    Rob

  7. Log in to comment