[Tutor] httplib exceptions

Alan Gauld alan.gauld at btinternet.com
Wed Aug 8 23:34:00 CEST 2007


"Bob Larsen" <bob at pbsit.com> wrote

It won't help with your problem but...

>            try:
>                page = urllib2.urlopen(url)
>                soup= page.read()
>                reex = re.compile(regex)
>                test = re.findall(reex,soup)

You could change this to

                  test = reex.findall(soup)

Its normal when compiling a regex to use the methods
of the compiled expression rather than to pass the
compiled regex to a module function.

>            except ValueError,e:
>                return 0
>            if test:
>                return 1
>            else:
>                return 0

And the if/else could be replaced with

return bool(test)

And on the real problem:

> There is a python Bug:
> http://sourceforge.net/tracker/index.php?func=detail&aid=1486335&group_id=5470&atid=105470
> <http://sourceforge.net/tracker/index.php?func=detail&aid=1486335&group_id=5470&atid=105470>
> that states this is caused by a missing EOF, and is "not a big deal"

Any chance that you are running into OS differences? eg Checking a 
Unix file on
a Windows box or vice versa? Windows expects an EOF at the end of a 
file,
Unix doesn't. Not sure what happens when you add in the complexity of
sucking the file across the net though...

Alan G. 




More information about the Tutor mailing list