undetected-chromedriver icon indicating copy to clipboard operation
undetected-chromedriver copied to clipboard

Issue creating multiple drivers [ subprocess : TypeError: expected str, bytes or os.PathLike object, not NoneType ]

Open ultrafunkamsterdam opened this issue 2 years ago • 3 comments

Actually there seems something wrong using ~~threading.threads and mp.processes, as well as asyncio or even in the main thread~~

when creating multiple drivers.

I don't know why i even bother since creating multiple drivers is useless and solves no problems. chromedriver is just a messaging proxy passing messages back and forth. and 1 driver can control dozens of windows, each containing a magnitude of tabs (and is designed for that)

that having said

note: all the below has also been done using the (use_subprocess=True)

in Ipython this works fine:

drivers = [uc.Chrome() for _ in range(20) ]

however, when creating a file:

... 
stuff
...
some other stuff
...

if __name__ == '__main__':

    drivers = [uc.Chrome() for _ in range(10)] 
    input("press a key to exit")

running this file yields:

    browser = subprocess.Popen(
  File "C:\ProgramData\Python39-32\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\ProgramData\Python39-32\lib\subprocess.py", line 1360, in _execute_child
    args = list2cmdline(args)
  File "C:\ProgramData\Python39-32\lib\subprocess.py", line 565, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "C:\ProgramData\Python39-32\lib\os.py", line 822, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType

thinking of a solution i tried modifying the code to put the path in a class variable when the first instance starts. but of course this won't work as it is not thread-safe.

workaround

So the ONLY solution for now (which is a bit cumbersome, so actually fits perfectly in creating multiple chromedrivers ;))
but does the job i :

putting the full path to your chrome BROWSER executable in the constructor

like so

 drivers = [uc.Chrome(browser_executable_path=r"c:\program files\x\y\z\chrome.exe") for _ in range(135)] 

Raising this as an issue since that is hip

(and I don't yet started documentation, nor know where to start, nor have time). so this is FYI

ultrafunkamsterdam avatar Jul 14 '22 09:07 ultrafunkamsterdam

Any solutions?

RFG-G avatar Feb 24 '23 07:02 RFG-G

i am stuck on this

thuydao avatar Nov 22 '23 14:11 thuydao

Solution:

To address the problem, you can modify the code as follows:

drivers = [
    uc.Chrome(
        version_main=114,  # Specify your browser version
        browser_executable_path="/path/of/chrome",  # Provide the path of the Chrome browser
        driver_executable_path="path/uc/driver",  # Specify the path of the UC driver
    )
    for _ in range(135)
]

To obtain the path of the UC driver, run a single instance chrome using UC. It will create the driver in a specific directory based on your operating system:

Windows: ~/appdata/roaming/undetected_chromedriver Linux: ~/.local/share/undetected_chromedriver Adjust the paths accordingly based on your system configuration.

Raguggg avatar Jan 20 '24 03:01 Raguggg