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

find_chrome_executable() bug #215

Closed
ganyu87 opened this issue Apr 25, 2024 · 3 comments · Fixed by #228
Closed

find_chrome_executable() bug #215

ganyu87 opened this issue Apr 25, 2024 · 3 comments · Fixed by #228
Labels
bug Something isn't working dev for dev branch

Comments

@ganyu87
Copy link

ganyu87 commented Apr 25, 2024

i write script into script.py and call it with script.php from website (not CLI)

script.py

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.binary_location = "/usr/bin/google-chrome"
async with webdriver.Chrome(options=options, debug=True) as self.driver:
    await self.main()

i got this error:

File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/www/wwwroot/45.77.173.161/mutasi/Amuba/src/BCA/bca.py", line 59, in run
    options = webdriver.ChromeOptions()
  File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/site-packages/selenium_driverless/types/options.py", line 52, in __init__
    self._binary_location = find_chrome_executable()
  File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/site-packages/selenium_driverless/utils/utils.py", line 38, in find_chrome_executable
    for item in os.environ.get("PATH").split(os.pathsep):
AttributeError: 'NoneType' object has no attribute 'split'

In some reason script.py which called by script.php can not get PATH environment. so the PATH value will be None. Which cause this problem
Note:
php => can get the PATH environment
python CLI => can get the PATH environment
python script called by php => can not get the PATH environment (idk why this is happend -_- )

i have no problem with my own script. because i still can fix it with:

if(os.environ.get('PATH') is None):
    if(platform.system()=='Windows'):
        os.environ["PATH"] = "" #should be Program Files and Program Files (x86) here
    else:
        os.environ["PATH"] = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.binary_location = "/usr/bin/google-chrome"
async with webdriver.Chrome(options=options, debug=False) as self.driver:
    await self.main()

The reason why open this issue is because of this code:

A. Minor Issue

self._binary_location = find_chrome_executable()

above code will try to find all chrome candidates, before i put the options.binary_location

options = webdriver.ChromeOptions() # find all chrome executable candidate
options.binary_location = "/usr/bin/google-chrome" # override the candidate
async with webdriver.Chrome(options=options, debug=True) as self.driver:
    await self.main()

i think we can let self._binary_location=None first. Then we can try find candidate if self._binary_location is None when webdriver.Chrome() called. But if this is too complicated to fix, i think we can ignore it right now

B. Major Issue

if IS_POSIX:
for item in os.environ.get("PATH").split(os.pathsep):
for subitem in (
"google-chrome",
"chromium",
"chromium-browser",
"chrome",
"google-chrome-stable",
):
candidates.add(os.sep.join((item, subitem)))

There is no None checking, so if PATH is not found in environment , it will cause fatal error.
I think that you just forgot it, because for Windows, you already have None checking

Thanks

@kaliiiiiiiiii kaliiiiiiiiii added bug Something isn't working dev for dev branch labels Apr 25, 2024
@kaliiiiiiiiii
Copy link
Owner

@ganyu87 Thanks a lot, will definitely fix it

kaliiiiiiiiii added a commit that referenced this issue May 23, 2024
- fix #215
- add option to support not adding the mv3 extension
- sync docs
@kaliiiiiiiiii kaliiiiiiiiii mentioned this issue May 23, 2024
@kaliiiiiiiiii
Copy link
Owner

uhh yeah let's hope I haven't put any bug in there:)
@ganyu87 can you confirm this to be fixed now btw?

@kaliiiiiiiiii
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dev for dev branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants