How can I return XML from boto calls?

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

Here is the challenge I am making:

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

Here is the response value (personal information deleted explicitly)

 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')) 

This is not ideal because I have another eBay sales module that works with the XML returned by ebaysdk-python. Amazon formats its XML in the same way as eBay, so if I could get the XML returned by Amazon instead of the format above, it would be brilliant.

I noticed that if I use boto.set_stream_logger('boto') , it will print the returned XML, maybe I could use this somehow?

This is what I would like to return:

 <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> 

Then I could use Python xml.etree.ElementTree to parse and manipulate the data.

+7
python xml amazon-web-services amazon-mws boto
source share
1 answer

I don't think there is an officially supported method for this, but you can do this to easily get a raw XML response:

 # 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... 
+2
source share

All Articles