maximum recursion in "re" module?

CJ Kucera pez at apocalyptech.com
Mon Oct 15 20:56:17 EDT 2001


Greetings, list!

I'm having a problem using the "re" module that's got me somewhat
boggled.  I'm using Python to automate downloading of bands off of
mp3.com.  What you do is pass a band's URL in to the program,
and it'll download all the songs available by that artist.  I have
this all working on my box at work, which is still running Python
1.5.2, but when I'm trying it out at home, using Python 2.1, it
dies, saying "RuntimeError: maximum recursion limit exceeded."
If it did this consistently, I wouldn't mind, but it seems to only
happen for certain bands.

I'm rather stumped.  When I strip out everything unnecessary from
the program, you end up with this:

#!/usr/bin/env python
import urllib, re, string, sys
if (len(sys.argv) == 2):
  # Regular Expressions
  startString = ".*?Lo Fi Play</phrase></a> <phrase><a href=\""
  mp3 = urllib.urlopen(sys.argv[1])
  mp3String = mp3.read()
  mp3String = string.replace(mp3String, "\n", "")
  
  # This line errors out:
  mp3String = re.compile(startString, re.I).sub("", mp3String, 1)
  print "Whee!  I made it through!"

Running this against one band works fine:

> pez at arrakis:~/bin$ ./temp.py http://artists.mp3s.com/artists/33/android_lust.html
> Whee!  I made it through!

But when I try another band:

> pez at arrakis:~/bin$ ./temp.py http://artists.mp3s.com/artists/103/this_ascension.html
> Traceback (most recent call last):
>   File "./temp.py", line 11, in ?
>     mp3String = re.compile(startString, re.I).sub("", mp3String, 1)
>   File "/usr/local/lib/python2.1/sre.py", line 164, in _sub
>     return _subn(pattern, template, string, count)[0]
>   File "/usr/local/lib/python2.1/sre.py", line 179, in _subn
>     m = c.search()
> RuntimeError: maximum recursion limit exceeded

So what gives?  Is there a size limit for the string?  The first
band returns about 50k of HTML, whereas the second returns 80k, but
since this works fine for Python 1.5.2 I'd expect it to work
for 2.1 . . .  I also checked manually to make sure that the string
I'm searching for exists in both pages, and it does.

So anyway, if someone could help me out here, I'd really appreciate
it.  Thanks much!

-CJ

WOW: Rapacious           | A priest advised Voltaire on his death bed to
apocalyptech.com/wow     |  renounce the devil.  Replied Voltaire, "This
pez at apocalyptech.com     |              is no time to make new enemies."




More information about the Python-list mailing list