Python Errno 10060] 连接尝试失败,因为连接方在一段时间后没有正确响应

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14143198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 10:35:47  来源:igfitidea点击:

Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time

pythonhttppython-2.7

提问by madhu131313

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

我像这样调用了这个函数,check_web_server('www.python.org',80,'/')但它给了我这个错误 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

你可以在这里清楚地看到代码 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.

我已经在 Stackoverflow 中搜索过这里,但我没有找到任何相关问题,对不起,我是网站的新手,如果我做错了什么。

采纳答案by sb9

As pingworks, but telnetto port 80does not, the HTTP port 80is 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:

至于ping作品,但telnet端口80没有,HTTP端口80是关闭你的机器上。我假设您的浏览器的 HTTP 连接通过代理(在浏览工作时,您将如何阅读 stackoverflow?)。您需要向 Python 程序添加一些代码来处理代理,如下所述:

Using an HTTP PROXY - Python

使用 HTTP 代理 - Python