2024-04-25 14:28:56 发布
网友
有没有办法设置mechanize在HTTP请求因超时而失败时重试它?或者我需要将它放入一个无限循环中,并在请求成功时使它脱离循环?在
您需要自己测试超时异常。以下未经测试的代码显示了这一想法:
import mechanize import socket timeout_occurred = False br = mechanize.Browser() try: br.open("http://python.org/", timeout=0.001) except mechanize.URLError as exc: if isinstance(exc.reason, socket.timeout): timeout_occurred = True if timeout_occurred: # retry br.open("http://python.org/", timeout=0.001)
此外,您还需要阅读有关超时如何工作的常见问题解答。在
您需要自己测试超时异常。以下未经测试的代码显示了这一想法:
此外,您还需要阅读有关超时如何工作的常见问题解答。在
相关问题 更多 >
编程相关推荐