【发布时间】:2016-07-23 19:18:30
【问题描述】:
我正在尝试运行以下代码,
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>
这是我的代理设置。
非常感谢任何帮助
【问题讨论】:
-
对我来说连接成功了。防火墙、防病毒软件或可以阻止的东西?
-
Michael,代码在给出错误之前运行了几个循环。即使防火墙关闭,没有防病毒软件,我也会收到错误:(
-
多少次迭代?我可以毫无问题地执行 100 次。你对响应对象做了什么?你有其他联系吗?他们可能会因为在很短的时间内进行多次访问而阻止了您的 IP。
-
大约 60 次迭代它工作正常。我正在将 html 表中的数据捕获到我的数据框中。有什么办法可以防止这种阻塞吗?我没有其他同时连接。 time.sleep(secs) 会起作用吗?
-
time.sleep(60) 完成了这项工作。非常感谢迈克尔 :)