httplib / connection

rhXX rh00667 at gmail.com
Tue Jun 12 08:47:02 EDT 2007


On Jun 12, 2:09 pm, rhXX <rh00... at gmail.com> wrote:
> hi all,
>
> i'm using this tutorial example
>
> import httplib
>
> h = httplib.HTTP("www.python.org")
> h.putrequest('GET','/index.html')
> h.putheader('User-Agent','Lame Tutorial Code')
> h.putheader('Accept','text/html')
> h.endheaders()
>
> errcode,errmsg, headers = h.getreply()
> f = h.getfile() # Get file object for reading data
> data = f.read()
> f.close()
>
> but always i get this tracing error, a timeout in h.endheaders()
>
>   File "ejemplo.py", line 331, in testA
>     h.endheaders()
>
>   File ".../lib/python2.4/httplib.py", line 795, in endheaders
>     self._send_output()
>
>   File ".../lib/python2.4/httplib.py", line 676, in _send_output
>     self.send(msg)
>
>   File ".../lib/python2.4/httplib.py", line 643, in send
>     self.connect()
>
>   File ".../lib/python2.4/httplib.py", line 627, in connect
>     raise socket.error, msg
>
> socket.error: (110, 'Connection timed out')
>
> must i do something about network before????
>
> i would appreciate ur commenst


sorry, the timeout induced me to think about proxy connection
(evident ....). i found this example and worked fine!
        import httplib, getpass, base64

	print "Proxy Authentication Required:"
	user = raw_input("Username: ")
	passwd = getpass.getpass()
	auth = base64.encodestring(user + ":" + passwd)

	proxy_domain = "proxy.toto.com"
	proxy_port = 8000

	host = "www.tata.com"
	url = "/"

	h = httplib.HTTPConnection(proxy_domain, proxy_port)
	h.putrequest('GET', "http://%s%s"%(host,url))
	h.putheader('Host', host)
	h.putheader('Proxy-Authorization', '''Basic %s''' % auth)
	h.endheaders()
	r = h.getresponse()
	z = r.read()

	print z

sorry by disturb ....





More information about the Python-list mailing list