0
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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
panch mukesh
  • 87
  • 1
  • 8
  • 2
    always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Dec 16 '19 at 06:24
  • @furas Thanks for suggestion. I have edited the description with full trace error. – panch mukesh Dec 16 '19 at 06:31
  • it is strange behavior. Maybe there is invisible char which makes problem. Do you have this problem when you run exactly this file directly in console/terminal/cmd.exe without `Spyder`? What if you create new file in Spyder and write code manually (without using copy-paste)? – furas Dec 16 '19 at 07:31
  • There are no issues in executing in cmd.exe, however when I am trying to execute it from Anaconda Prompt window similar error pops up. – panch mukesh Dec 16 '19 at 07:52
  • 1
    it would means that file and code is OK but problem has only anaconda and problem is in file `selenium\webdriver\remote\errorhandler.py`. Maybe if you reinstall module `selenium` in Anaconda then it will work correctly. Or you can open file `errorhandler.py` in text editor which has function `"convert tabs to spaces"` and use this fucntion and save it back to the same file. – furas Dec 16 '19 at 09:00
  • Thanks a lot @furas. It actually worked, somehow the file errorhandler.py got some spaces for which this issue was raised. – panch mukesh Dec 16 '19 at 09:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/204327/discussion-between-panch-mukesh-and-furas). – panch mukesh Dec 16 '19 at 10:00

2 Answers2

2

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.

furas
  • 134,197
  • 12
  • 106
  • 148
1

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 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 , 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352