【问题标题】:Python Selenium TypeError: argument of type 'TimeoutException' is not iterablePython Selenium TypeError:“TimeoutException”类型的参数不可迭代
【发布时间】:2020-11-15 11:31:02
【问题描述】:

我正在运行 Python Selenium 脚本,有时,当互联网连接不工作时,我会遇到两种类型的错误:

timeout: Timed out receiving message from renderer: 300.000

unknown error: net::ERR_PROXY_CONNECTION_FAILED

所以我想做这个;每次出现这 2 个错误中的一个时,运行我笔记本电脑上的另一个脚本

这是我的代码的相关部分:

        except Exception as e:
            print(e)
            line_count += 1
            if "Timed out" in e:
                os.system(r"C:\Users\SAMSUNG\script.py")
                print("Done")
                pass
            else:
                print("Not Concerned Error")
                pass

            if "ERR_PROXY" in e:
                os.system(r"C:\Users\SAMSUNG\script.py")
                print("Done")
                pass
            else:
                print("Not Concerned Error")
                pass

但它不起作用!这是我的错误:

if "Timed out" in e:
TypeError: argument of type 'TimeoutException' is not iterable

【问题讨论】:

  • 我想你会找到答案的here

标签: python python-3.x selenium timeout


【解决方案1】:

您需要先将Exception 实例转换为字符串:

if "Timed out" in str(e): 

如果您要进行多次检查,则进行一次转换:

str_e = str(e)
...
if "Timed out" in str_e:
...
if "ERR_PROXY" in str_e:

【讨论】:

    猜你喜欢
    • 2012-04-26
    • 1970-01-01
    • 2022-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多