httplib and Proxy

Rolf Wester wester at ilt.fraunhofer.de
Fri Nov 21 09:52:14 CET 2003


Rolf Wester wrote:
> Hi,
> 
> I want to fetch some web-pages via http. I know how to do this without a 
> proxy server in between but unfortunately we can only access the 
> internet via a proxy. I would be very appriciative if anybody could tell 
> me how to do this.
> 
> Thanks in advance
> 
> Rolf Wester
> 
> P.S.: I would not mind to use sockets directly
> 
Hi,

thank you all for your help. I tried urllib, httplib and sockets.


With urllib:

f = urllib.urlopen("http://www.python.org/index.html")

I get:

...
invalid proxy for http: 'cache.ilt.fhg.de:81'


httplib works:

conn = httplib.HTTPConnection("cache.ilt.fhg.de", 81)
conn.request("GET", "http://www.python.org/index.html")
r = conn.getresponse()
print r.status, r.reason
print r.msg
while 1:
     data = r.read(1024)
     if len(data) < 1024: break
     print data

and so do sockets:

HOST = 'cache.ilt.fhg.de'
PORT = 81
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('GET http://www.python.org/index.html HTTP/1.1\r\nAccept: 
text/plain\r\n\r\n')
while 1:
     data = s.recv(1024)
     print data
     if len(data) < 1024: break
s.close()

Thanks again

Rolf Wester





More information about the Python-list mailing list