作为e的例外。 e在调试器中不可见

时间:2018-10-25 11:50:57

标签: python python-3.x

Python 3.6

def get_results(drv):
    try:
        table_element = WebDriverWait(drv,60).until(EC.presence_of_element_located((By.TAG_NAME, "tbody")))
    except TimeoutException as e:
        raise TimeoutException(e.message)

屏幕截图:https://b.radikal.ru/b05/1810/52/65f03791c2e2.png

    Traceback (most recent call last):
      File "/home/michael/PycharmProjects/PoiskOptim/keyword_stuffing.py", line 56, in get_results
        table_element = WebDriverWait(drv, 60).until(EC.presence_of_element_located((By.TAG_NAME, "tbody")))
      File "/home/michael/PycharmProjects/PoiskOptim/venv/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until
        raise TimeoutException(message, screen, stacktrace)
    selenium.common.exceptions.TimeoutException: Message:


    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/home/michael/Documents/pycharm-community-2018.2.3/helpers/pydev/pydevd.py", line 1664, in <module>
        main()
      File "/home/michael/Documents/pycharm-community-2018.2.3/helpers/pydev/pydevd.py", line 1658, in main
        globals = debugger.run(setup['file'], None, None, is_module)
      File "/home/michael/Documents/pycharm-community-2018.2.3/helpers/pydev/pydevd.py", line 1068, in run
        pydev_imports.execfile(file, globals, locals)  # execute the script
      File "/home/michael/Documents/pycharm-community-2018.2.3/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
        exec(compile(contents+"\n", file, 'exec'), glob, loc)
      File "/home/michael/PycharmProjects/PoiskOptim/main.py", line 14, in <module>
        funcs[choice]()
      File "/home/michael/PycharmProjects/PoiskOptim/keyword_stuffing.py", line 141, in keyword_stuffing
        parse_all(phrases)
      File "/home/michael/PycharmProjects/PoiskOptim/keyword_stuffing.py", line 134, in parse_all
        handle_chunks(drv, phrases)
      File "/home/michael/PycharmProjects/PoiskOptim/keyword_stuffing.py", line 81, in handle_chunks
        get_results(drv)
      File "/home/michael/PycharmProjects/PoiskOptim/keyword_stuffing.py", line 58, in get_results
        raise TimeoutException(e.message)
    AttributeError: 'TimeoutException' object has no attribute 'message'

您能帮我了解这里发生了什么吗?我将TimeoutException设置为e。好吧,我希望e至少在调试器中可见。但不是。在上下文中没有e。

稍后添加 问题是:为什么上下文中没有e

1 个答案:

答案 0 :(得分:1)

这很明显。您尝试访问message变量的e属性,该属性恰好是类型TimeoutException的对象。在Python3中,Exception对象不再具有message属性。如果要打印异常消息,请使用str(e)