使用Anaconda的Spyd时,压痕是否有问题

2024-10-05 14:23:31 发布

您现在位置:Python中文网/ 问答频道 /正文

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

这个代码片段在Anaconda的Spyder中运行时弹出一个缩进错误。此错误如下:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Panch\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Users\Panch\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 29, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "C:\Users\Panch\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 27, in <module>
    from .remote_connection import RemoteConnection
  File "C:\Users\Panch\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 34, in <module>
    from .errorhandler import ErrorCode
  File "C:\Users\Panch\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242
    raise exception_class(message, screen, stacktrace)
                                                     ^

缩进错误:未缩进与任何外部缩进级别不匹配

如果我遗漏了什么,请告诉我。你知道吗


Tags: infromimportremotelocalseleniumlineusers
2条回答

这是一种奇怪的行为,但可能是文件selenium\webdriver\remote\errorhandler.py被破坏了。你知道吗

您可以在具有函数"convert tabs to spaces"的文本编辑器中打开此文件,使用此函数并将其保存回同一个文件。你知道吗

此错误消息。。。你知道吗

IndentationError: unindent does not match any outer indentation level

…意味着代码行中存在缩进问题。你知道吗

显然,在您发布的代码行中,我没有看到任何缩进问题。但是,也有可能在选项卡中混入空格字符。你知道吗


解决方案

根据您使用的IDE,有以下不同的解决方案:

  • 尝试搜索所有选项卡并用一些空格替换它们,因为Spacesindentation的首选方法。你知道吗
  • 中,您可以通过选中取消选中来使用制表符进行缩进:

    View  > Indentation  > Convert Indentation to Tabs
    
  • 要解决制表符/空格问题,可以使用tabnanny,如下所示:

    python -m tabnanny your_python_file.py
    
  • 在Python编辑器中,选择所有代码/文本并执行以下操作:

    Go to Format -> Untabify Region
    
  • 如果您正在使用,请按Esc并执行以下操作以自动缩进所有内容,并清除所有空格。

  • Atom上,转到:

    Packages > Whitespace > Convert Spaces to Tabs
    

相关问题 更多 >