Errno 10060] A connection attempt failed because t

2020-02-21 08:21发布

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.

1条回答
迷人小祖宗
2楼-- · 2020-02-21 08:50

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

查看更多
登录 后发表回答