如果发生超时,则在for()循环中传递迭代

时间:2014-06-04 13:20:17

标签: python exception-handling python-requests

我有一个methodtry/catch使用request requests一些网址。

如果发生超时(在except中),如何修改我的代码以继续执行for循环中的下一个req

我尝试用python中的passbreak语句做一些功课,但似乎都不合适。

try:
    request = requests.get(the_path, timeout=1.0, verify=False)
        for req in request:
            if inst.val in req:
                print req
except requests.exceptions.Timeout:
    print 'We timed out'
    <somehow continue to next iteration of req>

有人可以告诉我如何做到这一点吗?谢谢

1 个答案:

答案 0 :(得分:1)

我认为你要找的是continue声明。

相关问题