ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.62k stars 1.15k forks source link

Freeze_support #503

Open misterpeople opened 2 years ago

misterpeople commented 2 years ago

Hey, im getting this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "C:\Python39\lib\multiprocessing\spawn.py", line 125, in _main
    prepare(preparation_data)
  File "C:\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "C:\Python39\lib\runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Python39\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\PC\Desktop\Bots\test.py", line 12, in <module>
    driver = uc.Chrome(options=options, version_main=94)  # version_main allows to specify your chrome version instead of following chrome global version
  File "C:\Python39\lib\site-packages\undetected_chromedriver\__init__.py", line 356, in __init__
    self.browser_pid = start_detached(
  File "C:\Python39\lib\site-packages\undetected_chromedriver\dprocess.py", line 30, in start_detached
    multiprocessing.Process(
  File "C:\Python39\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Python39\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Python39\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "C:\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "C:\Python39\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()
                ...

I have python 3.9.2, Chromedriver Version 98 & I've installed pip install undetected-chromedriver

Can someone help me? thanks

misterpeople commented 2 years ago

Im trying to do chrome Automatication like logging in a website

ToasterUwU commented 2 years ago

@misterpeople I posted this on another issue as well. Since this here is the same error and problem as the other one, you should take a look at the fix I found. Just click the link below.

https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/486#issuecomment-1032009193

misterpeople commented 2 years ago

@misterpeople I posted this on another issue as well. Since this here is the same error and problem as the other one, you should take a look at the fix I found. Just click the link below.

#486 (comment)

Thank you, Im getting another error maybe because im pointing it to Chromedriver? Im new in all of this maybe you could help?


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
if __name__ == "__main__":

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://www.google.com/")
print(driver.title)

Error:

File "C:\Users\PC\Desktop\Bots\NewALi.py", line 7
    PATH = "C:\Program Files (x86)\chromedriver.exe"
    ^
IndentationError: expected an indented block
[Finished in 528ms]
QIN2DIM commented 2 years ago

Welcome to the Python community!


import webbrowser

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

STACKOVERFLOW_SEARCH_API = "https://stackoverflow.com/search?"

if __name__ == "__main__":
    service = Service(ChromeDriverManager(log_level=0).install())
    driver = Chrome(service=service)  # noqa

    try:
        driver.get("https://www.google.com/")
        print(driver.title)
    except Exception as e:
        webbrowser.open(STACKOVERFLOW_SEARCH_API + f"q={e}")
    finally:
        driver.quit()
ToasterUwU commented 2 years ago

@misterpeople

@QIN2DIM did the right thing. You just need to indent the stuff. For everything like "if", "for", "while", and all these things, you need to indent everything that is in that once more than the actual "for", "if", etc statement.

Welcome to the Python Community.

misterpeople commented 2 years ago

Welcome to the Python community!

import webbrowser

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

STACKOVERFLOW_SEARCH_API = "https://stackoverflow.com/search?"

if __name__ == "__main__":
    service = Service(ChromeDriverManager(log_level=0).install())
    driver = Chrome(service=service)  # noqa

    try:
        driver.get("https://www.google.com/")
        print(driver.title)
    except Exception as e:
        webbrowser.open(STACKOVERFLOW_SEARCH_API + f"q={e}")
    finally:
        driver.quit()

@misterpeople

@QIN2DIM did the right thing. You just need to indent the stuff. For everything like "if", "for", "while", and all these things, you need to indent everything that is in that once more than the actual "for", "if", etc statement.

Welcome to the Python Community.

Thank you both! although I dont see a use of the "import undetected_chromedriver.v2" Shouldnt it be there?

ToasterUwU commented 2 years ago

Welcome to the Python community!

import webbrowser

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

STACKOVERFLOW_SEARCH_API = "https://stackoverflow.com/search?"

if __name__ == "__main__":
    service = Service(ChromeDriverManager(log_level=0).install())
    driver = Chrome(service=service)  # noqa

    try:
        driver.get("https://www.google.com/")
        print(driver.title)
    except Exception as e:
        webbrowser.open(STACKOVERFLOW_SEARCH_API + f"q={e}")
    finally:
        driver.quit()

@misterpeople @QIN2DIM did the right thing. You just need to indent the stuff. For everything like "if", "for", "while", and all these things, you need to indent everything that is in that once more than the actual "for", "if", etc statement. Welcome to the Python Community.

Thank you both! although I dont see a use of the "import undetected_chromedriver.v2" Shouldnt it be there?

@misterpeople We didn't check if your code works. Just wanted to explain that all the code that does something more than making a variable or import something, should be within that specific if statement. If you need that import statement, just add it.

ToasterUwU commented 2 years ago

@ultrafunkamsterdam i think you can close this one