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)
^
缩进错误:未缩进与任何外部缩进级别不匹配
如果我遗漏了什么,请告诉我。你知道吗
这是一种奇怪的行为,但可能是文件
selenium\webdriver\remote\errorhandler.py
被破坏了。你知道吗您可以在具有函数
"convert tabs to spaces"
的文本编辑器中打开此文件,使用此函数并将其保存回同一个文件。你知道吗此错误消息。。。你知道吗
…意味着代码行中存在缩进问题。你知道吗
显然,在您发布的代码行中,我没有看到任何缩进问题。但是,也有可能在选项卡中混入空格字符。你知道吗
解决方案
根据您使用的IDE,有以下不同的解决方案:
在sublimetext中,您可以通过选中或取消选中来使用制表符进行缩进:
要解决制表符/空格问题,可以使用
tabnanny
,如下所示:在Python编辑器中,选择所有代码/文本并执行以下操作:
如果您正在使用vim,请按Esc并执行以下操作以自动缩进所有内容,并清除所有空格。
在Atom上,转到:
相关问题 更多 >
编程相关推荐