Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7003257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:02:38+00:00 2026-05-27T21:02:38+00:00

I am trying to parse an XML response from Amazon’s Product Advertising API, this

  • 0

I am trying to parse an XML response from Amazon’s Product Advertising API, this is the xml

<?xml version="1.0" ?>
    <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2010-11-01"> <OperationRequest>
        <HTTPHeaders>
            <Header Name="UserAgent" Value="TSN (Language=Python)"></Header>
        </HTTPHeaders>
        <RequestId>96ef9bc3-68a8-4bf3-a2c7-c98b8aeae00f</RequestId>
        <Arguments>
            <Argument Name="Operation" Value="ItemLookup"></Argument>
            <Argument Name="Service" Value="AWSECommerceService"></Argument>
            <Argument Name="Signature" Value="gjc4wRNum3YT82app1d06vMIDM7v44fOmZTP8Uh3LqE="></Argument><Argument Name="AssociateTag" Value="sneakick-20"></Argument>
            <Argument Name="Version" Value="2010-11-01"></Argument>
            <Argument Name="ItemId" Value="810056013349,810056013264"></Argument>
            <Argument Name="IdType" Value="UPC"></Argument>
            <Argument Name="AWSAccessKeyId" Value="AKIAIFMUMJLJOOINRVRA"></Argument>
            <Argument Name="Timestamp" Value="2012-01-03T21:26:39Z"></Argument>
            <Argument Name="ResponseGroup" Value="ItemIds"></Argument>
            <Argument Name="SearchIndex" Value="Apparel"></Argument>
        </Arguments>
       <RequestProcessingTime>0.0595830000000000</RequestProcessingTime>
      </OperationRequest>
      <Items>
          <Request>
              <IsValid>True</IsValid>
              <ItemLookupRequest>
                  <IdType>UPC</IdType>
                  <ItemId>810056013349</ItemId>
                  <ItemId>810056013264</ItemId>
                  <ResponseGroup>ItemIds</ResponseGroup>
                  <SearchIndex>Apparel</SearchIndex>
                  <VariationPage>All</VariationPage>
              </ItemLookupRequest>
          </Request>
          <Item>
              <ASIN>B000XR4K6U</ASIN>
          </Item>
          <Item>
              <ASIN>B000XR2UU8</ASIN>
          </Item>
       </Items>
    </ItemLookupResponse>

All i am interested in is the Item tags inside Items , so basically all that xml was returned by amazon in a string which i parsed like so:

from xml.etree.ElementTree import fromstring

response = "xml string returned by amazon"
parsed = fromstring(response)
items = parsed[1] # This is how i get the Items element

# These were my attempts at getting the Item element
items.find('Item')
items.findall('Item')

items being the Items element, but so far no success, it keeps returning None/Empty , im i missing something , or is there another way to go about this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:02:39+00:00Added an answer on May 27, 2026 at 9:02 pm

    It is a namespace issue. This works:

    from xml.etree import ElementTree as ET
    
    XML = """<?xml version="1.0" ?>
        <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2010-11-01"> 
          <OperationRequest>
            <HTTPHeaders>
                <Header Name="UserAgent" Value="TSN (Language=Python)"></Header>
            </HTTPHeaders>
            <RequestId>96ef9bc3-68a8-4bf3-a2c7-c98b8aeae00f</RequestId>
            <Arguments>
                <Argument Name="Operation" Value="ItemLookup"></Argument>
                <Argument Name="Service" Value="AWSECommerceService"></Argument>
                <Argument Name="Signature" Value="gjc4wRNum3YT82app1d06vMIDM7v44fOmZTP8Uh3LqE="></Argument>
                <Argument Name="AssociateTag" Value="sneakick-20"></Argument>
                <Argument Name="Version" Value="2010-11-01"></Argument>
                <Argument Name="ItemId" Value="810056013349,810056013264"></Argument>
                <Argument Name="IdType" Value="UPC"></Argument>
                <Argument Name="AWSAccessKeyId" Value="AKIAIFMUMJLJOOINRVRA"></Argument>
                <Argument Name="Timestamp" Value="2012-01-03T21:26:39Z"></Argument>
                <Argument Name="ResponseGroup" Value="ItemIds"></Argument>
                <Argument Name="SearchIndex" Value="Apparel"></Argument>
            </Arguments>
           <RequestProcessingTime>0.0595830000000000</RequestProcessingTime>
          </OperationRequest>
          <Items>
              <Request>
                  <IsValid>True</IsValid>
                  <ItemLookupRequest>
                      <IdType>UPC</IdType>
                      <ItemId>810056013349</ItemId>
                      <ItemId>810056013264</ItemId>
                      <ResponseGroup>ItemIds</ResponseGroup>
                      <SearchIndex>Apparel</SearchIndex>
                      <VariationPage>All</VariationPage>
                  </ItemLookupRequest>
              </Request>
              <Item>
                  <ASIN>B000XR4K6U</ASIN>
              </Item>
              <Item>
                  <ASIN>B000XR2UU8</ASIN>
              </Item>
           </Items>
        </ItemLookupResponse>"""
    
    NS = "{http://webservices.amazon.com/AWSECommerceService/2010-11-01}"
    
    doc = ET.fromstring(XML)
    Item_elems = doc.findall(".//" + NS + "Item")  # All Item elements in document
    
    print Item_elems
    

    Output:

    [<Element '{http://webservices.amazon.com/AWSECommerceService/2010-11-01}Item' at 0xbf0c50>, 
    <Element '{http://webservices.amazon.com/AWSECommerceService/2010-11-01}Item' at 0xbf0cd0>]
    

    Variation closer to your own code:

    NS = "{http://webservices.amazon.com/AWSECommerceService/2010-11-01}"
    doc = ET.fromstring(XML)
    items = doc[1]                           # Items element
    
    first_item = items.find(NS + 'Item')     # First direct Item child
    all_items =  items.findall(NS + 'Item')  # List of all direct Item children
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse this XML string: <?xml version=1.0 encoding=UTF-8 standalone=no?> <response type=success> <lots>
I am trying to parse following SOAP response coming from Savon SOAP api <?xml
I'm trying to parse the xml response of http://api.hostip.info/?ip=12.215.42.19 with SimpleXML but I can't
I am getting this error while trying to Parse the Xml response from the
I am trying to use xml.etree.ElementTree to parse responses from eBay finding API, findItemsByProduct.
I'm trying to parse the xml document returned from this link but I get
I am trying to parse an XML response from a website in C#. The
Trying to parse some XML but apparently this is too much for a lazy
So I'm trying to parse an xml file: <?xml version=1.0 encoding=utf-8 ?> <Root> <att1
I am beginner in PHP. I am trying to parse this xml file. <relationship>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.