23
def check_web_server(host, port, path):
        h = httplib.HTTPConnection(host, port)
        h.request('GET',path)
        resp = h.getresponse()
        print 'HTTP Response:'
        print '   status =', resp.status
        print '   reason =', resp.reason
        print 'HTTP Headers:'
        for hdr in resp.getheaders():
                print '  %s: %s' % hdr

I called this function like this check_web_server('www.python.org',80,'/') but it gave me this error error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

You can see the code clearly here http://pastebin.com/V9KpGkvw

I have searched here in Stackoverflow but I didnt find any relevant questions sorry I am new to site ,if I Did anything wrong.

Kimvais
  • 38,306
  • 16
  • 108
  • 142
madhu131313
  • 7,003
  • 7
  • 40
  • 53
  • 2
    Must be your setup, works for me. Try `ping www.python.org` and `telnet www.python.org 80` in your shell to see if python.org actually is reachable from your development setup. – Kimvais Jan 03 '13 at 16:47
  • it is reachable using ping www.python.org – madhu131313 Jan 03 '13 at 16:50
  • 2
    Works fine here, must be related to some problem with your configuration. – sb9 Jan 03 '13 at 16:51
  • @Madhu13 Did you try the `telnet www.python.org 80`? What was the result? (If you get a connection, try typing `GET /` followed by Enter and see if you get a response.) – Mattie Jan 03 '13 at 19:05
  • @zigg with the telnet I am getting error "Could not open connection to the host, on port 80 : connection failed" – madhu131313 Jan 04 '13 at 05:32

1 Answers1

18

As ping works, but telnetto port 80 does not, the HTTP port 80 is closed on your machine. I assume that your browser's HTTP connection goes through a proxy (as browsing works, how else would you read stackoverflow?). You need to add some code to your python program, that handles the proxy, like described here:

Using an HTTP PROXY - Python

Community
  • 1
  • 1
sb9
  • 1,082
  • 7
  • 18
  • 1
    This is probably the right answer, but I think the more accurate diagnosis is not that port 80 is necessarily "closed on [OP's] machine", which implies a local service is not listening, but rather that port 80 access to www.python.org is blocked, be it by firewall (either local or remote) or some other network condition. – Mattie Jan 04 '13 at 13:08
  • 1
    You are right, but that's what I also meant. "closed" should be a synonym for "not accessible", regardless wheather blocked locally or by firewall – sb9 Jan 04 '13 at 13:14