【问题标题】:Amazon Product Advertising API (ItemSearch with ItemPage)亚马逊产品广告 API(ItemSearch 和 ItemPage)
【发布时间】:2012-05-30 23:20:02
【问题描述】:

我写了以下代码:

from hashlib import sha256
from base64 import b64encode
import hmac
import urllib
from time import strftime, gmtime

url = 'http://ecs.amazonaws.com/onca/xml'
AWSAccessKeyId = amazon_settings.amazon_access_key_id
AssociateTag = amazon_settings.amazon_associate_tag
Keywords = urllib.quote_plus('Potter')
Operation = 'ItemSearch'
SearchIndex = 'Books'
Service = 'AWSECommerceService'
Timestamp = urllib.quote_plus(strftime("%Y-%m-%dT%H:%M:%S.000Z", gmtime()))
Version = '2011-08-01'

sign_to = 'GET\necs.amazonaws.com\n/onca/xml\nAWSAccessKeyId=%s&AssociateTag=%s&Keywords=%s&Operation=%s&SearchIndex=%s&Service=%s&Timestamp=%s&Version=%s' % (AWSAccessKeyId, AssociateTag, Keywords, Operation, SearchIndex, Service, Timestamp, Version)

Signature = urllib.quote_plus(b64encode(hmac.new(str(amazon_settings.amazon_secret_access_key), str(sign_to), sha256).digest()))

request = '%s?AWSAccessKeyId=%s&AssociateTag=%s&Keywords=%s&Operation=%s&SearchIndex=%s&Service=%s&Timestamp=%s&Version=%s&Signature=%s' % (url, AWSAccessKeyId, AssociateTag, Keywords, Operation, SearchIndex, Service, Timestamp, Version, Signature)

print request

当我使用此代码时一切正常。 但是,如果我尝试将 ItemPage 参数添加到 sign_to 变量并请求变量,我会收到错误 SignatureDoesNotMatch。

请帮帮我。

【问题讨论】:

    标签: python web-services api amazon-web-services amazon


    【解决方案1】:

    实际上并没有回答你的问题,但我建议你看看亚马逊产品广告 API 的优秀 python 包装器 - python-amazon-product-api

    【讨论】:

      【解决方案2】:

      在文档中很难找到,但您必须确保您的操作列表按字母顺序排列,否则您会收到 SignatureDoesNotMatch 错误。

      例如,ItemPage 必须介于 AssociateTagKeywords 之间才有效。

      AWSAccessKeyId
      AssociateTag
      ItemPage
      Keywords
      Operation
      ResponseGroup
      SearchIndex
      Service
      SignatureVersion
      Timestamp
      Version
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-29
        • 1970-01-01
        相关资源
        最近更新 更多