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:
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
i write script into
script.py
and call it withscript.php
from website (not CLI)script.py
i got this error:
In some reason
script.py
which called byscript.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:
The reason why open this issue is because of this code:
A. Minor Issue https://github.com/kaliiiiiiiiii/Selenium-Driverless/blob/88625e998c510e6db0df5ec2563d7d826f131c18/src/selenium_driverless/types/options.py#L52
above code will try to find all chrome candidates, before i put the
options.binary_location
i think we can let
self._binary_location=None
first. Then we can try find candidate ifself._binary_location is None
whenwebdriver.Chrome()
called. But if this is too complicated to fix, i think we can ignore it right nowB. Major Issue https://github.com/kaliiiiiiiiii/Selenium-Driverless/blob/88625e998c510e6db0df5ec2563d7d826f131c18/src/selenium_driverless/utils/utils.py#L37-L46 There is no
None
checking, so ifPATH
is not found in environment , it will cause fatal error. I think that you just forgot it, because for Windows, you already haveNone
checkingThanks