如何从boto调用返回XML? [英] How can I return XML from boto calls?

查看:67
本文介绍了如何从boto调用返回XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python 2.7.6中使用 boto 2.32.1 .我在 list_orders <上遇到问题/a> boto的mws模块的功能来获取我的亚马逊订单的XML数据.

I am using boto 2.32.1 with Python 2.7.6. I am having problems with the list_orders function of boto's mws modules to get the XML data of my Amazon orders.

这是我打的电话:

response = connection.list_orders(CreatedAfter='2014-08-26T05:53:44+00:00', 
   MarketplaceId=['XXXXXXXXXXXXX'])

这是response的值(明显删除了个人信息)

Here is the value of response (with personal information removed obviously)

ListOrdersResponse{u'xmlns': u'https://mws.amazonservices.com/Orders/2013-09-01'}
(ListOrdersResult: ListOrdersResult{}
(CreatedBefore: u'2014-08-26T10:06:10Z', Orders: ^Orders^{}
(Order: [Order{}(***ORDER INFORMATION***)])), 
ResponseMetadata: ^ResponseMetadata^{}(RequestId: u'xxxxxxxxxx'))

这不是理想的,因为我还有一个用于eBay销售的模块,该模块可与ebaysdk-python返回的XML一起使用.亚马逊的XML格式与eBay相似,因此,如果我能得到亚马逊返回的XML而不是上面的格式,那就太好了.

This isn't ideal because I have another module for eBay sales that works with the XML returned by ebaysdk-python. Amazon formats their XML similarly to eBay so if I could get the XML returned by Amazon instead of the format above, it would be brilliant.

我已经注意到,如果使用boto.set_stream_logger('boto'),它将打印返回的XML,所以也许我可以以某种方式利用它?

I have noticed that if I use boto.set_stream_logger('boto'), it will print the XML returned so maybe I could take advantage of that somehow?

这就是我想退回的东西:

This is what I would like to be returned:

<ListOrdersResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
  <ListOrdersResult>
    <Orders>
      <Order>
        ***ORDER INFORMATION***
      </Order>
    </Orders>
    <CreatedBefore>2014-08-26T10:18:59Z</CreatedBefore>
  </ListOrdersResult>
  <ResponseMetadata>
    <RequestId>XXXXXXXXXXXXXXXXXXXXXXXXXXXXX</RequestId>
  </ResponseMetadata>
</ListOrdersResponse>

然后我可以使用Python的xml.etree.ElementTree来解析和处理数据.

I could then use Python's xml.etree.ElementTree to parse and work with the data.

推荐答案

我认为没有官方支持的方法可以执行此操作,但是您可以执行以下操作以轻松获取原始XML响应:

I don't think there's an officially supported method to do this, but you can do this to get the raw XML response back easily:

# Set up
from boto.mws.connection import MWSConnection
MWSConnection._parse_response = lambda s, x, y, z: z

# Usage
result = az.get_matching_product_for_id(MarketplaceId="ATVPDKIKX0DER",
                                            SearchIndex="Books",
                                            IdType="ASIN",
                                            IdList=[0439023521])
# <?xml version="1.0"?>\n<GetMatchingProductForIdResponse xmlns...

这篇关于如何从boto调用返回XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆