Reputation: 164
I have a python script that launches a headless webdriver. The exact same code works with no issues on CentOS7. I'm trying to run it on an Amazon Linux
google-chrome --version output is Google Chrome 83.0.4103.61
chromedriver --version output is ChromeDriver 83.0.4103.39
Here's the function
def LoadWebDrivers():
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--start-maximized')
options.add_argument('--window-size=800,600')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=443')
global WebDriver
WebDriver = webdriver.Chrome(executable_path=driverPath,options=options)
WebDriver.get('site')
return WebDriver
If I run chrome directly from the CLI, I get this (there are also a bunch of Fontconfig warnings which I read can be ignored)
[3779:3779:0520/015819.096591:ERROR:browser_main_loop.cc(1473)] Unable to open X display.
[0520/015819.108227:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
Segmentation fault
The script fails with this
File "/home/ec2-user/.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/ec2-user/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/ec2-user/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/ec2-user/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/ec2-user/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
After enabling logging, here's what the log file spit out (multiple entries of the devtools error)
[0520/021834.142267:ERROR:socket_posix.cc(148)] bind() failed: Permission denied (13)
[0520/021834.143153:ERROR:socket_posix.cc(148)] bind() failed: Permission denied (13)
[0520/021834.143191:ERROR:devtools_http_handler.cc(298)] Cannot start http server for devtools.
[1589941174.014][DEBUG]: DevTools HTTP Request: http://localhost:443/json/version
[1589941174.015][DEBUG]: DevTools HTTP Request failed
[1589941174.076][INFO]: [1d7ba4dc7a13a3e6bce467b1e3c51393] RESPONSE InitSession ERROR chrome not reachable
[1589941174.076][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1589941174.076][DEBUG]: Log type 'browser' lost 0 entries on destruction
Upvotes: 0
Views: 2132
Reputation: 164
After looking at the logs error404 asked me to add and seeing
[0520/021834.142267:ERROR:socket_posix.cc(148)] bind() failed: Permission denied (13)
[0520/021834.143153:ERROR:socket_posix.cc(148)] bind() failed: Permission denied (13)
[0520/021834.143191:ERROR:devtools_http_handler.cc(298)] Cannot start http server for devtools.
I ran the script as sudo and it successfully loads now.
Upvotes: 0
Reputation: 2823
Try with below settings in additional to the above. Also add some logging at verbose level.
chromedriver_path = "<chromedriver_binary_path>"
outputdir = "<log_dir_path>"
service_log_path = "{}/chromedriver.log".format(outputdir)
service_args = ['--verbose']
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=chromedriver_path, service_log_path=service_log_path, service_args=service_args, options=chrome_options)
driver.get(url)
Upvotes: 1