python - 如何使用 boto mws 提取亚马逊特定订单数据

标签 python boto amazon-mws

我正在尝试弄清楚如何使用 boto 提取各种亚马逊卖家帐户数据。但是,我似乎找不到与此相关的任何示例。 以下代码不会返回错误,但也不会返回任何有用的数据(注释掉的打印订单行除外,它似乎返回有用的数据)。

from boto.mws.connection import MWSConnection 

merchantId = 'zzzz' 
marketplaceId = 'zzz' 
accessKeyId = 'zzzz' 
secretKey = 'secret' 

mws = MWSConnection(accessKeyId, secretKey, Merchant=merchantId) 

orders = mws.list_orders(CreatedAfter='2015-10-23T12:00:00Z', MarketplaceId = 
[marketplaceId])
#print orders

theData = mws.get_order(AmazonOrderId='xxx-xxxxxx-xxxxx')

print theData

有关如何获取上述特定订单关联数据的任何提示吗?

最佳答案

你的orders变量看起来不错,这就是打印显示数据的原因,但它可能很难理解。据我所知,boto 创建了从网络响应翻译而来的自定义对象。最有用的文档是 Amazon MWS Dev Guideboto mws documentation 。如果您仔细观察,您会发现所有方法都可以组合在一起。

您的代码存在的问题是您的 list_orders 请求返回订单列表。您需要解析列表以获取每个订单的 ID。由于 list_orders 方法已经返回订单信息,因此 get_order 调用是多余的。

以下代码应该可以工作,尽管尚未测试。

from boto.mws.connection import MWSConnection 

merchantId = 'zzzz' 
marketplaceId = 'zzz' 
accessKeyId = 'zzzz' 
secretKey = 'secret' 

mws = MWSConnection(accessKeyId, secretKey, Merchant=merchantId) 

orders = mws.list_orders(CreatedAfter='2015-10-23T12:00:00Z', MarketplaceId = 
[marketplaceId])

for order in orders.ListOrdersResult.Orders.Order:
    this_order_id = order.AmazonOrderId
    theData = mws.get_order(AmazonOrderId = this_order_id)
    print theData
    #do what you want with the data
    #
    #EXAMPLE GET ORDER ITEMS
    order_items = mws.list_order_items(AmazonOrderId = this_order_id)
    print order_items

关于python - 如何使用 boto mws 提取亚马逊特定订单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33324925/

相关文章:

Delphi - Amazon MWS API - 如何从 SHA 256 HMAC 派生 Base64 HMAC?

amazon-web-services - 如何从亚马逊市场API检索服务费明细

python - 如何使用另一个列表作为键的引用来更改 Python 3.5 字典中键的顺序?

python - 用户存在但无法使用 simpleJWT 和 Django Admin 进行身份验证

python - 如何使用 boto3 获取 aws 中存在的实例和卷以及负载均衡器的总数?

amazon-mws - 如何通过 mws api 从亚马逊库存中删除产品

python - django:gettext 和强制转换为 unicode

python - 从任务中调用 Java/Scala 函数

boto - 来自 : can't read/var/mail/boto. s3.connection

python - 无法在两个 boto.cfg 文件之间切换