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

  • SEARCH
  • Home
  • 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 3355290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:22:35+00:00 2026-05-18T02:22:35+00:00

I have a small issue. I am trying to pull some data from my

  • 0

I have a small issue. I am trying to pull some data from my XML using lxml and I keep getting a “list index out of range” error, now I am trying to get the [0] position of my list, which should be the first one but it keeps giving me the error.

Here is a code snippet (thanks to MattH for helping me out):

req2 = urllib2.Request("web_url/public/api.php?path_info=/projects&token=##############")
        resp = urllib2.urlopen(req2)
        resp_data = resp.read()
        if not resp.code == 200 and resp.headers.get('content-type') == 'text/xml':
          # Do your error handling.
          raise Exception('Unexpected response',req2,resp)
        data = etree.XML(resp_data)
        api_id = int(data.xpath('/project/id/text()')[0])
        project.API_id = api_id
        project.save()

Now when I do a print statement, it pulls the XML so I know that I have xml data and its not blank, but not sure what else could be causing this?

Thanks!

Steve

  • 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-18T02:22:36+00:00Added an answer on May 18, 2026 at 2:22 am

    With your XML document’s structure being

    <projects>
        <projects>
            <id>
                ...
            </id>
        </project>
    </projects>
    

    your XPath expression /project/id/text() surely won’t match anything, and the accessing index 0 of the empty XPath result list of course results in an IndexError.

    Instead of /project, which only matches a root (!) element called "project", you might want to use /projects/project or //project. So a correct XPath for your XML structure would be //project/id/text().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're having a small issue and could use some help - we have the
I have a small utility that I use to download an MP3 file from
I have a small VB.NET application that I'm working on using the full version
I'm trying to get some information from ebay api and store it in database
I have a small program where I have been trying to create collections of
I have a small unmanaged c++ application, I'm trying to use CoCreateInstance(...) to create
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I have small problem with my .net 2.0 winforms application. I want to embed
Where I work, we have small teams of 2 - 5 people. As a
I have a small JS function that does Ajax for me and another like

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.