httplib / connection

Discussion in 'Python' started by rhXX, Jun 12, 2007.

  1. rhXX

    rhXX Guest

    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
     
    rhXX, Jun 12, 2007
    #1
    1. Advertising

  2. rhXX

    rhXX Guest

    On Jun 12, 2:09 pm, rhXX <> 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 ....
     
    rhXX, Jun 12, 2007
    #2
    1. Advertising

  3. En Tue, 12 Jun 2007 09:09:12 -0300, rhXX <> escribió:

    > i'm using this tutorial example


    Glad to see you could make it work finally. Which tutorial was that? The
    httplib.HTTP class that you were using is very old and deprecated for
    several years now.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Jun 12, 2007
    #3
  4. rhXX

    rhXX Guest

    > The
    > httplib.HTTP class that you were using is very old and deprecated for
    > several years now.
    >
    > --
    > Gabriel Genellina


    :-( oh ...., tks!

    i took it from

    www.ug.it.usyd.edu.au/~comp5315/lec-09.html

    which class must i use?

    tks in advance
     
    rhXX, Jun 13, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John J. Lee

    Re: How to upload a file with httplib?

    John J. Lee, Jun 27, 2003, in forum: Python
    Replies:
    1
    Views:
    2,286
  2. hitectahir
    Replies:
    0
    Views:
    371
    hitectahir
    Jul 1, 2003
  3. Bobbie
    Replies:
    2
    Views:
    754
    Jordan Krushen
    Jul 21, 2003
  4. Rich
    Replies:
    3
    Views:
    323
  5. berklee just berklee

    httplib usage for images

    berklee just berklee, Aug 19, 2003, in forum: Python
    Replies:
    0
    Views:
    289
    berklee just berklee
    Aug 19, 2003
Loading...

Share This Page