Getting web page throught a proxy (squid)
Steven Adams
adams_s at lab.eng.usyd.edu.au
Tue Mar 21 21:22:29 EST 2000
Jean-Paul ROUMIAN wrote:
>
> Hello,
>
> I try to get a web page,from behind a proxy (squid) which uses the ICP
> protocol.
> Is there a module that can do that (httplib can't as far as I know) ?
>
> (I need also a ssl-connection, but I've found patches for this)
>
> Any pointers ?
>
> Jean-Paul ROUMIAN
Hi,
I had to had to do exactly this, didn't need ssl though,
here's a quick script that gets a webpage via proxy, and prints it out
to screen (not too useful, but its only an example :-)
--code--
import httplib
PROXY = 'yourproxyname:yourproxyport'
URL='http://www.some.server/somefile.html'
h = httplib.HTTP(PROXY)
h.putrequest('GET',URL)
h.putheader('Accept','text/html')
h.endheaders()
errcode,errmsg,headers = h.getreply()
print errcode
file = h.getfile()
data = file.read()
file.close()
print data
--code--
OK, so it ain't pretty, and it doesn't check that the errorcode is 200
before getting file.
but that was how I realised it was SQUID running as proxy.
hope that helps
Steven
More information about the Python-list
mailing list