Is there something issue in indentation, while using Anaconda's Spyder

随声附和 提交于 2021-02-11 13:36:01

问题


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

This code snippet pops an error of indentation while running in Anaconda's Spyder. This the below error:

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)
                                                     ^

IndentationError: unindent does not match any outer indentation level

Please let me know if anything I am missing out.


回答1:


It is strange behavior but maybe somehow file selenium\webdriver\remote\errorhandler.py was broken.

You can open this file in text editor which has function "convert tabs to spaces", use this function and save it back to the same file.




回答2:


This error message...

IndentationError: unindent does not match any outer indentation level

...implies that there are indentation issues with in the lines of code.

Apparently, I don't see any indentation issue with in the lines of code you have published. However, there is a possibility of Space characters mixed in with your Tab.


Solution

There are different solutions as per the IDE you are using as follows:

  • Try to search and replace all the tabs with a few spaces as Spaces are the preferred method for indentation.
  • In sublimetext you can set or unset by checking or unchecking to use tabs for indentation:

    View --> Indentation --> Convert Indentation to Tabs
    
  • To fugure out the tabs/spaces issue you can use tabnanny as follows:

    python -m tabnanny your_python_file.py
    
  • Within the Python editor, select all the code/text and do the following:

    Go to Format -> Untabify Region
    
  • Incase you are using vim, press Esc and do the following to auto indent everything and will clear up any spaces you have .

  • On Atom, go to:

    Packages > Whitespace > Convert Spaces to Tabs
    


来源:https://stackoverflow.com/questions/59351371/is-there-something-issue-in-indentation-while-using-anacondas-spyder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!