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

start error, TypeError: expected str, bytes or os.PathLike object, not NoneType #497

Open
evensonliu opened this issue Feb 15, 2022 · 5 comments

Comments

@evensonliu
Copy link

evensonliu commented Feb 15, 2022

Hi,
I meet this error below, and I cannot solve it. Coud you help me ?

d = uc.Chrome(use_subprocess=True)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\38957\anaconda3\lib\site-packages\undetected_chromedriver_init_.py", line 362, in init
browser = subprocess.Popen(
File "C:\Users\38957\anaconda3\lib\subprocess.py", line 858, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\38957\anaconda3\lib\subprocess.py", line 1251, in _execute_child
args = list2cmdline(args)
File "C:\Users\38957\anaconda3\lib\subprocess.py", line 553, in list2cmdline
for arg in map(os.fsdecode, seq):
File "C:\Users\38957\anaconda3\lib\os.py", line 818, in fsdecode
filename = fspath(filename) # Does type-checking of filename.
TypeError: expected str, bytes or os.PathLike object, not NoneType

This error shows no matter "use_subprocess=True" is set or not.

[Environmant]

  • Python 3.8.8 (default, Apr 13 2021, 15:08:07) [MSC v.1916 32 bit (Intel)] :: Anaconda, Inc. on win32

  • undetected-chromedriver, both 3.1.2 and 3.1.3

  • chrome 98.0.4758.82(64)

@evensonliu
Copy link
Author

Reason Found:

find_chrome_executable cannot find the path of my Chrome.exe
This was caused in init.py:639 ~ 640.

    for item in map(
        os.environ.get, ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA")
    ):
        for subitem in (
            "Google/Chrome/Application",
            "Google/Chrome Beta/Application",
            "Google/Chrome Canary/Application",
        ):
            candidate

I test it:

m = map(os.environ.get, ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA"))
for i in m:print(i)
output:
C:\Program Files (x86)
C:\Program Files (x86)
C:\Users\me\AppData\Local

Actully, my Chrome.exe is located in:

"C:\Program Files\Google\Chrome\Application\chrome.exe"

@evensonliu
Copy link
Author

in some windows system, os.environ.get("PROGRAMFILES") will alwasy return "C:\Program Files (x86)",

if you want to find "C:\Program Files", you should use os.environ.get("ProgramW6432 ")

so

for item in map(
os.environ.get, ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA")
):

need change to :

for item in map(
os.environ.get, ("PROGRAMFILES", "ProgramW6432", "PROGRAMFILES(X86)", "LOCALAPPDATA")
):

refers:

@saif-byte
Copy link

@evensonliu Hi, I have tried what you suggested but it still does not work.
Here is the error:
Traceback (most recent call last): File "C:\Users\DC\OneDrive\Desktop\check.py", line 5, in <module> driver = uc.Chrome(executable_path = 'C:\SeleniumDrivers\chromedriver.exe') File "C:\Users\DC\AppData\Local\Programs\Python\Python39\lib\site-packages\undetected_chromedriver\__init__.py", line 421, in __init__ browser = subprocess.Popen( File "C:\Users\DC\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\DC\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1356, in _execute_child args = list2cmdline(args) File "C:\Users\DC\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 561, in list2cmdline for arg in map(os.fsdecode, seq): File "C:\Users\DC\AppData\Local\Programs\Python\Python39\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

@bengabp
Copy link

bengabp commented Apr 24, 2023

@evensonliu , @saif-byte , I got this stuff working. So i was running my script periodically using the crontab service in linux. The actual problem here is that the interpreter somehow was not able to find the chromium executable and then it gave that error:
So i had to manually navigate into that directory and execute chomium myself
image

Then i went to my code and edited the initialization line
from this:

driver = Chrome(version_main=112)

to this:

driver = Chrome(version_main=112,browser_executable_path="/snap/bin/chromium")

The browser_executable_path parameter is the path to the chromium executable. Sorry my solution is for linux but i think windows users can easily change this in their own code .

@aiteerzhao
Copy link

browser_executable_path

thanks!

driver = Chrome(version_main=112, browser_executable_path="/snap/bin/chromium")
in this param,use 'executable_path' on windows,but on linux to use 'browser_executable_path'.I resoved my problem!

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

4 participants