python urlopen 错误 [Errno 10060]

python urlopen error [Errno 10060]

我正在尝试 运行 以下代码,

for parname in parss:
    data = {'action': 'listp', 'parish': parname}
    data = urllib.urlencode(data)
    req = urllib2.Request('http://www.irishancestors.ie/search/townlands/ded_index.php', data)
    response = urllib2.urlopen(req)

但我在代码执行后几分钟收到错误

urllib2.URLError: <urlopen 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>

这是我的代理设置。

非常感谢任何帮助

如评论中所述,在很短的时间内执行大量请求会导致服务器(尤其是网络服务器)阻止您的连接尝试。

这是一种常见的网络自动攻击反制措施。 根据服务器的不同,在请求之间等待很短的时间应该可以解决您的问题。

您还可以使用更动态的方法。首先,尽可能多地执行请求,中间不要等待。如果请求花费的时间比平时长得多,很可能是超时,您必须等待。此时,您取消您的请求,等待并重试。如果后续尝试也导致超时,则等待时间加倍。通过这个称为 自适应退避 的过程,您应该(希望)能够以最小的开销访问您想要的数据。