简体   繁体   English

适用于python的Amazon Product API-我无法弄清一个奇怪的错误

[英]Amazon Product API for python - A strange error that I can't figure out

Here is the situation, I'm trying to get this API to work for me, but I can't seem to figure out all of its quirks. 在这种情况下,我正在尝试使该API对我有用,但我似乎无法弄清其所有怪癖。 Even when I run the example below (taken from https://bitbucket.org/basti/python-amazon-product-api/src/2b6b628300c4/examples/all-galileo-titles.py ) I get random errors. 即使我运行下面的示例(取自https://bitbucket.org/basti/python-amazon-product-api/src/2b6b628300c4/examples/all-galileo-titles.py ),也会出现随机错误。 Now I'm getting an error that says the __init__() takes 4 arguments, and I'm only feeding it two. 现在我得到一个错误,说__init__()接受4个参数,而我只喂了两个。 I put all of the credentials in the correct place, though, and I can't find anywhere in the modules where __init__() is demanding extra arguments. 但是,我将所有凭据放置在正确的位置,而我在模块中的任何地方都找不到__init__()要求额外的参数。 Anyone have any thoughts? 有人有什么想法吗?

Here is what I was running. 这是我正在跑步的东西。 More details about the program can be found at that link above. 有关该程序的更多详细信息,请参见上方的链接。

from amazonproduct.api import API
import lxml

if __name__ == '__main__':

    # Don't forget to create file ~/.amazon-product-api
    # with your credentials (see docs for details)
    api = API(locale = 'uk')

    result = api.item_search('Books', Publisher= 'RosettaBooks',
        ResponseGroup='Large')

    # extract paging information
    total_results = result.results
    total_pages = len(result)  # or result.pages

    for book in result:

        print 'page %d of %d' % (result.current, total_pages)

        #~ from lxml import etree
        #~ print etree.tostring(book, pretty_print=True)

        print book.ASIN,
        print unicode(book.ItemAttributes.Author), ':',
        print unicode(book.ItemAttributes.Title),
        if hasattr(book.ItemAttributes, 'ListPrice'):
            print unicode(book.ItemAttributes.ListPrice.FormattedPrice)
        elif hasattr(book.OfferSummary, 'LowestUsedPrice'):
            print u'(used from %s)' % book.OfferSummary.LowestUsedPrice.FormattedPrice

I had the same problem, I found on the bitbucket site for python-amazon-product-api a question from a couple of years ago that enabled me to work around the problem. 我遇到了同样的问题,几年前我在python-amazon-product-api的bitbucket网站上发现了一个问题,使我能够解决该问题。 See 11/1/2011 new requirement AssociateTag -- update required? 请参阅2011年11月1日新要求AssociateTag-是否需要更新?

What I did to work around is not use the .amazon-product-api file to specify the credentials but instead pass them as part of the API call: 我要做的工作不是使用.amazon-product-api文件指定凭据,而是将它们作为API调用的一部分传递:

AWS_KEY = '……….'
SECRET_KEY = '……………'
ASSOCIATE_TAG = '…………….'
api = API(access_key_id=AWS_KEY, secret_access_key=SECRET_KEY, locale="us", associate_tag=ASSOCIATE_TAG)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM