我有一个Python 2.7脚本,它包括从数据库中打开/删除多个url并从网页中提取一些信息。代码可能需要8小时才能运行,我正在处理多个网站。
时不时(1-2小时),我在尝试打开一个URL时随机收到错误消息IOError: [Errno socket error] [Errno 10060]
IOError: [Errno socket 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
我试图通过在URL打开操作之间添加2秒的time.sleep(2)
暂停来避免该错误,但仍然得到错误。这个错误似乎与我试图打开URL的网站无关。
我想用try/except语句来防止脚本崩溃。
如果发生套接字错误,脚本将暂停大约20秒,然后重试打开URL。如果URL正确打开,请继续使用脚本。我正在使用urlopen()
打开url。
目前没有回答
相关问题 更多 >
编程相关推荐