[Zope] Re: urlopen works outside Zope, not inside
Bill Bell
bill-bell@bill-bell.hamilton.on.ca
Sun, 31 Mar 2002 08:06:36 -0500
Dieter Maurer <dieter@handshake.de> wrote:
>Bill Bell writes:
> > I have an External Method containing a reference to urlopen. The
>procedure
> > that the Method represents works well when invoked from outside of
>Zope. However, within Zope I get the 10061 socket error, "Connection
>refused."
> >
> > Help or advice, please.
>Are you sure, it gets the same parameters?
>
> "Connection refused" usually means, there is not server at the other
> end...
I am reasonably confident that this is true.
The following code runs successfully inside SciTE.
def getCount ( ):
from urllib import urlopen, quote
from string import find
searchFor =3D 'Cobol'
arg =3D=
r'http://jobsearch.monster.ca/jobsearch.asp?brd=3D1&cy=3DCA&lid=3D236&fn=
=3D6&fn=3D546&fn=3D660&fn=3D554&fn=3D561&q=3D%s' % ( quote ( searchFor), )
result =3D arg
try:
page =3D urlopen ( arg )
result +=3D '<br/>%s: ' % searchFor
for line in page.readlines():
loc =3D find ( line, "Jobs 1 to " )
if loc !=3D -1:
loc2 =3D find ( line, " of " )
loc3 =3D find ( line, "</B>", loc2 )
result +=3D line [ loc2 + 4 : loc3 ]
return result
result +=3D 'None found'
except Exception, msg:
result +=3D '<br/>' + str ( msg )
return result
if __name__ =3D=3D "__main__":
print getCount ( )
If I upload this into an External Method with function name "getCount" and=
then click on the 'Test' tab I get the following:
http://jobsearch.monster.ca/jobsearch.asp?brd=3D1&cy=3DCA&lid=3D236&fn=3D6&f=
n=3D546&fn=3D660&fn=3D554&fn=3D561&q=3DCobol<br/>[Errno socket error]=
(10061, 'Connection refused')
Would appreciate any more thoughts you might have.
Bill
------------
"It is the time that you have wasted for your rose that makes your rose so=
important."--St-Exupery