我正在尝试弄清楚如何使用 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 Guide和 boto 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/