CGI with URL problem

R

rodmc

-- 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")
 
R

Ralf Schönian

rodmc said:
-- 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
 
R

rodmc

Thanks for your reply, no one is running locally on my PC and the
other as the default user which occurs when the script is run through
a browser.

Best,

rod
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top