Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge bug in undetected-chromedriver v2 #384

Closed
Avnsx opened this issue Dec 5, 2021 · 17 comments
Closed

Huge bug in undetected-chromedriver v2 #384

Avnsx opened this issue Dec 5, 2021 · 17 comments

Comments

@Avnsx
Copy link

Avnsx commented Dec 5, 2021

it's unironically so big that I can't even load up undetected chromedriver v2 with the basic code from your ReadMe

import undetected_chromedriver.v2 as uc
driver = uc.Chrome()
driver.get('https://nowsecure.nl')

ouput:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\spawn.py", line 125, in _main
    prepare(preparation_data)
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "C:\ProgramData\Miniconda3\lib\runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\ProgramData\Miniconda3\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\ProgramData\Miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\canmi\Desktop\seleniumwire_red.py", line 391, in <module>
    driver = uc.Chrome()
  File "C:\ProgramData\Miniconda3\lib\site-packages\undetected_chromedriver\v2.py", line 299, in __init__
    self.browser_pid = start_detached(options.binary_location, *options.arguments)
  File "C:\ProgramData\Miniconda3\lib\site-packages\undetected_chromedriver\dprocess.py", line 30, in start_detached
    multiprocessing.Process(target=_start_detached, args=(executable, *args), kwargs={'writer': writer},
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "C:\ProgramData\Miniconda3\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Exception ignored in: <function Chrome.__del__ at 0x000001EBDEECB1F0>
Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\lib\site-packages\undetected_chromedriver\v2.py", line 647, in __del__
  File "C:\ProgramData\Miniconda3\lib\site-packages\undetected_chromedriver\v2.py", line 604, in quit
AttributeError: 'Chrome' object has no attribute 'service'

I did find a solution and that is just writing it into main:

if __name__ == '__main__':
    import undetected_chromedriver.v2 as uc
    driver = uc.Chrome()
    driver.get('https://nowsecure.nl')

but this is unacceptable and it is restricting me in freely formatting my code, also forcing me to use an entry point.
I'm encountering this bug in latest version of uc v2 and python 3.8.10 for windows 10
Please fix this as soon as possible @ultrafunkamsterdam 🙏🏼

@Avnsx Avnsx changed the title Huge bug in undetected-chromedriver Huge bug in undetected-chromedriver v2 Dec 5, 2021
@crane-denny
Copy link

@ultrafunkamsterdam
For some reasons I don't understand yet you are spawning a second instance of Chrome. At least I assume this because of a new user-data-dir. And the moment this happens it breaks.

I am now not sure what to do next. It could be that this lib is really not selenium 4 ready like you said in the readme. But then I would expect it to be set in setup.py to avoid conflicts.
I will leave this up to your hands since you know your code better then me. :)

@wildangunawan
Copy link

Downgrade to 3.0.3 as in this issue suggestion.

Also don't use Python 3.10 if you don't want to face another undetected-chromedriver bug

@koljaoh
Copy link

koljaoh commented Dec 15, 2021

Hope this gets a real fix soon (there are reasons why I can't use 3.0.3 and the if name == 'main': doesnt work in all cases)

@ultrafunkamsterdam
Copy link
Owner

all fixed

@Charcadet
Copy link

Charcadet commented Dec 23, 2021

all fixed

I'm still having the same issue.
UC 3.1.1
Python 3.7.8

import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://nowsecure.nl')

Gives me:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 114, in _main
    prepare(preparation_data)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Rico\Downloads\auto-bumper-master\auto-bumper\test.py", line 2, in <module>
    driver = uc.Chrome()
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 339, in __init__
    self.browser_pid = start_detached(options.binary_location, *options.arguments)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\dprocess.py", line 34, in start_detached
    daemon=True,
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Exception ignored in: <function Chrome.__del__ at 0x000002862E2C5948>
Traceback (most recent call last):
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 583, in __del__
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 539, in quit
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 367, in __getattribute__
AttributeError: 'Chrome' object has no attribute 'service'

@ultrafunkamsterdam
Copy link
Owner

you are clearly having multiple versions installed and not using the correct one.
"undetected_chromedriver\v2.py", line 604, in quit..."
v2.py only has 3 lines

@TheCamer1
Copy link

I am having exactly the same error, I'm on a fresh install of python 3.10 and undetected-chromedriver 3.0.3. @ultrafunkamsterdam could you please explain what the correct version is? I've been trying every answer in all these threads on this issue and it is not solving it.

@Charcadet
Copy link

you are clearly having multiple versions installed and not using the correct one. "undetected_chromedriver\v2.py", line 604, in quit..." v2.py only has 3 lines

Even after fully uninstalling undetected_chromedriver

C:\Users\Rico>pip uninstall undetected_chromedriver
Found existing installation: undetected-chromedriver 3.1.1
Uninstalling undetected-chromedriver-3.1.1:
  Would remove:
    c:\users\rico\appdata\local\programs\python\python37\lib\site-packages\undetected_chromedriver-3.1.1-py3.7.egg-info
    c:\users\rico\appdata\local\programs\python\python37\lib\site-packages\undetected_chromedriver\*
Proceed (y/n)? y
  Successfully uninstalled undetected-chromedriver-3.1.1

C:\Users\Rico>pip uninstall undetected_chromedriver
WARNING: Skipping undetected-chromedriver as it is not installed.
PS C:\Users\Rico\Downloads\auto-bumper-master\auto-bumper> py .\test.py
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 114, in _main
    prepare(preparation_data)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 225, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
    run_name="__mp_main__")
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Rico\Downloads\auto-bumper-master\auto-bumper\test.py", line 2, in <module>
    driver = uc.Chrome()
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 339, in __init__
    self.browser_pid = start_detached(options.binary_location, *options.arguments)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\dprocess.py", line 34, in start_detached
    daemon=True,
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
    _check_not_importing_main()
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Exception ignored in: <function Chrome.__del__ at 0x00000239F56F58B8>
Traceback (most recent call last):
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 583, in __del__
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 539, in quit
  File "C:\Users\Rico\AppData\Local\Programs\Python\Python37\lib\site-packages\undetected_chromedriver\__init__.py", line 367, in __getattribute__
AttributeError: 'Chrome' object has no attribute 'service'

This is still the code:

import undetected_chromedriver as uc
driver = uc.Chrome()
# known url using cloudflare's "under attack mode"
driver.get('https://nowsecure.nl')

Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)] on win32
Windows 10 Pro Version 20H2 (19043.928)
undetected-chromedriver-3.1.1

@ultrafunkamsterdam
Copy link
Owner

1 - A script called test.py is not a great idea.
2 - In fact this makes perfect sense.
Your program is simply exiting before chrome is fully spawned. if your program exits, chromedriver exits.. never been different except for the error, which is justifyable since some multiprocess black magic makes sure Chrome has no parent process.

It seems to me that what you're really looking for is a interactive session.
in that case, use ipython.

That all being said. I was able to reproduce, although it being an edge case, I have a "fix" for this, but i need to test it first. will commit later.

@Charcadet
Copy link

1 - A script called test.py is not a great idea. 2 - In fact this makes perfect sense. Your program is simply exiting before chrome is fully spawned. if your program exits, chromedriver exits.. never been different except for the error, which is justifyable since some multiprocess black magic makes sure Chrome has no parent process.

It seems to me that what you're really looking for is a interactive session. in that case, use ipython.

That all being said. I was able to reproduce, although it being an edge case, I have a "fix" for this, but i need to test it first. will commit later.

Even when running my main project I'm trying to use this with, which doesn't insta exit and is pretty long it doesn't run at all and throws the same error. Works fine with just selenium.

@sunny9495-dev
Copy link

sunny9495-dev commented Jan 26, 2022

Temporary Solution :
Install Python 3.7.9
Install 3.0.3(pip install -Iv undetected-chromedriver==3.0.3)
Use the code
import undetected_chromedriver.v2 as uc
driver = uc.Chrome(executable_path=r'drivers/chromedriver.exe', options=options, version_main=97)

@Avnsx
Copy link
Author

Avnsx commented Jan 26, 2022

Temporary Solution : Install Python 3.7.9 Install 3.0.3(pip install -Iv undetected-chromedriver==3.0.3) Use the code import undetected_chromedriver.v2 as uc driver = uc.Chrome(executable_path=r'drivers/chromedriver.exe', options=options, version_main=97)

Nah he actually fixed it in newest version, you just have to write uc.Chrome(use_subprocess=True)

@sunny9495-dev
Copy link

sunny9495-dev commented Jan 26, 2022

Temporary Solution : Install Python 3.7.9 Install 3.0.3(pip install -Iv undetected-chromedriver==3.0.3) Use the code import undetected_chromedriver.v2 as uc driver = uc.Chrome(executable_path=r'drivers/chromedriver.exe', options=options, version_main=97)

Nah he actually fixed it in newest version, you just have to write uc.Chrome(use_subprocess=True)

Tried with 3.1.3, didnt worked Avnsx, all the time i get
Error Permission denied 13 chromedriver.exe
whenever i select more than 1 thread

@Avnsx
Copy link
Author

Avnsx commented Feb 26, 2022

Temporary Solution : Install Python 3.7.9 Install 3.0.3(pip install -Iv undetected-chromedriver==3.0.3) Use the code import undetected_chromedriver.v2 as uc driver = uc.Chrome(executable_path=r'drivers/chromedriver.exe', options=options, version_main=97)

Nah he actually fixed it in newest version, you just have to write uc.Chrome(use_subprocess=True)

Tried with 3.1.3, didnt worked Avnsx, all the time i get Error Permission denied 13 chromedriver.exe whenever i select more than 1 thread

Error Permission denied 13 chromedriver.exe

not an issue with UC, but with your threading code

@st681
Copy link

st681 commented Mar 15, 2022

Temporary Solution : Install Python 3.7.9 Install 3.0.3(pip install -Iv undetected-chromedriver==3.0.3) Use the code import undetected_chromedriver.v2 as uc driver = uc.Chrome(executable_path=r'drivers/chromedriver.exe', options=options, version_main=97)

Nah he actually fixed it in newest version, you just have to write uc.Chrome(use_subprocess=True)

Fixed for me. Thank you so much bro !

@JMJAJ
Copy link

JMJAJ commented Apr 11, 2022

Guys, I love u. This help so much. Thanks

@shafeeralip
Copy link

Temporary Solution : Install Python 3.7.9 Install 3.0.3(pip install -Iv undetected-chromedriver==3.0.3) Use the code import undetected_chromedriver.v2 as uc driver = uc.Chrome(executable_path=r'drivers/chromedriver.exe', options=options, version_main=97)

Nah he actually fixed it in newest version, you just have to write uc.Chrome(use_subprocess=True)

Fixed for me Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests