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 8399621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:21:17+00:00 2026-06-09T21:21:17+00:00

I’m running a for loop to grab content out of some XML and it

  • 0

I’m running a for loop to grab content out of some XML and it works fine, until I reach around the 29th iteration. At that point it gives me this error:

File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch
  return self.handle_exception(e, self.app.debug)   
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch
  return method(*args, **kwargs)   
File "J:\Art & Graphic Design\Graphic Design\Websites\lawvoter-dev\cron_congressman.py", line 64, in get
  birthday      = re.findall("<birthday>(.*)</birthday>",element)[0] 
IndexError: list index out of range

The code is:

for element in members:
            title         = re.findall("<title>(.*)</title>",element)[0]
            role          = re.findall("<role_type_label>(.*)</role_type_label>",element)[0]
            name_sortable = re.findall("<name_sortable>(.*)</name_sortable>",element)[0]
            firstname     = re.findall("<firstname>(.*)</firstname>",element)[0]
            lastname      = re.findall("<lastname>(.*)</lastname>",element)[0]
            gender        = re.findall("<gender_label>(.*)</gender_label>",element)[0]
            birthday      = re.findall("<birthday>(.*)</birthday>",element)[0]
            party         = re.findall("<party>(.*)</party>",element)[0]
            state         = re.findall("<state>(.*)</state>",element)[0]
            description   = re.findall("<description>(.*)</description>",element)[0]
            start_date    = re.findall("<startdate>(.*)</startdate>",element)[0]
            end_date      = re.findall("<enddate>(.*)</enddate>",element)[0]
            website       = re.findall("<website>(.*)</website>",element)[0]
            bioguideid    = re.findall("<bioguideid>(.*)</bioguideid>",element)[0]
            osid          = re.findall("<osid>(.*)</osid>",element)[0]
            pvsid         = re.findall("<pvsid>(.*)</pvsid>",element)[0]
            twitterid     = re.findall("<twitterid>(.*)</twitterid>",element)[0]
            youtubeid     = re.findall("<youtubeid>(.*)</youtubeid>",element)[0]

            member = Congressman(title=title, role=role, name_sortable=name_sortable, firstname=firstname, lastname=lastname, gender=gender, birthday=birthday, party=party, state=state,
                                 description=description, start_date=start_date, end_date=end_date, website=website, bioguideid=bioguideid, osid=osid, pvsid=pvsid, twitterid=twitterid, youtubeid=youtubeid)
            member.put()

I really don’t get why this error is popping up? It always works fine for the first 29 iterations? The each element in the datamodel is also set to “default=None” just in case. However, when I look at the XML itself, and go to the exact line where the error happens, the value is actually there. Anyone know why it would give an error even though the value exists?

  • 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-06-09T21:21:18+00:00Added an answer on June 9, 2026 at 9:21 pm

    it looks like

    birthday      = re.findall("<birthday>(.*)</birthday>",element)[0]
    

    returns an empty list and you are trying to extract the first element which is not in the list and it throws the

    IndexError: list index out of range
    

    like here:

    >>> l = []
    >>> l[0]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IndexError: list index out of range
    >>> 
    

    EDIT:

    import re, logging
    
    def findelement(item, element):
        i = re.findall(item, element)
        if not i:
            logging.info('no item found for %s with element %s' %(item, element))
            return ''
        return i[0]
    
    
    for element in members:
        title = findelement("<title>(.*)</title>", element)
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
I am currently running into a problem where an element is coming back from

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.