HTTP getreply() never returns

Steve Holden steve at holdenweb.com
Thu Apr 19 15:39:33 EDT 2007


Marko.Cain.23 at gmail.com wrote:
> Hi,
> 
> I have the following code which send/receive HTTP request/response:
> 
>    # where sampleUrl is '127.0.0.1' and
>    # url is 'www.cnn.com'
> 
>    h = httplib.HTTP(self.sampleUrl, 8080)
>         h.putrequest('GET', '/sample?url=' + self.url)
>         h.endheaders()
> 
>         errcode, errmsg, headers = h.getreply()
> 
> But it never returns from h.getreply().
> 
> I am using python 2.3.4. Can you please tell me what am I missing?
> I am sure the url is correctly. I try putting this 'http://
> 127.0.0.1:8080/sample?url=www.cnn.com' and it works.
> 
> Thank you for any help.
> 

  >>> h = httplib.HTTP("www.cnn.com", 80)
  >>> h.putrequest('GET', "/")
  >>> h.endheaders()
  >>> c, m, h = h.getreply()
  >>> c
200
  >>> m
'OK'
  >>> h
<httplib.HTTPMessage instance at 0x7ff3414c>
  >>> h.getheaders("content-type")
['text/html']

The above shows you the basics of using httplib - if your own server 
isn't responding that's probably not the library's fault. What is the 
server? Perhaps its implementation of the HTTP protocol is slightly off, 
but not so far off that browsers can't work with it.

For what it's worth you *do* appear to have formed the calls correctly, 
so something a little more complex is going on here.

You might consider using WireShark (nee Ethereal) to look at the data 
passing across the wire when you use the browser and when you use 
httplib then comparing the data. That won't work on Windows because it 
disobligingly refuses to let you tap into the loopback (127) network.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list