CGI with URL problem

Ralf Schönian ralf at schoenian-online.de
Tue Feb 12 23:28:40 EST 2008


rodmc schrieb:
> -- sorry if this has shown up twice, but my browser crashed and ended
> up posting the message when I hit the space bar for some odd reason.
> Also it was not quite ready.
> 
> Hi,
> 
> I am writing a small CGI app which tests if another webpage exists,
> the pages are on a Wiki system. Anyway when I run the same function
> (see below) from within IDLE it is ok, however when it is run from
> within the CGI script I get a socket error::
> 
> "URLError:
>       reason = <socket.error instance>"
> 
> I am not quite sure what is causing this, is there a special way of
> dealing with such things from within CGI script? I have pasted the
> offending function below, along with only the import statement which
> relates to that function.
> 
> Thanks in advance for any help.
> 
> Kind regards,
> 
> rod
> 
> From the CGI version:
> 
> from urllib2 import urlopen as urlopen
> 
> def urlexists(url):
>         path="http://x.y.z/wiki/index.php?title="+url
>         sock = urlopen(path)
>         page=sock.read()
>         if "There is currently no text in this page" in page:
>                 return True
>         else:
>                 return False
> 
> Ammended IDLE version:
> 
> from urllib2 import urlopen as urlopen
> import os,sys
> 
> def urlexists(url):
>         path="http://x.y.z/wiki/index.php?title="+url
>         sock = urlopen(path)
>         page=sock.read()
>         if "There is currently no text in this page" in page:
>                 print "found"
>                 return True
>         else:
>                 print "not found"
>                 return False
> 
> if __name__=="__main__":
>     urlexists("cheese_test")

Are you using the same user in your cgi script and within IDLE?

Ralf Schoenian



More information about the Python-list mailing list