unable to run selenium chrome-driver on google-cloud-run

给你一囗甜甜゛ 提交于 2020-06-28 04:47:24

问题


I have a docker container that runs a working selenium chrome driver script, however when the same image is deployed to Google Cloud Run I encounter the following error.

webdriver.Chrome('/home/vmagent/app/chromedriver', chrome_options=self.options) File "/env/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/env/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

Here is the process I used to verify the code works running the docker image locally.

docker run -it <image_id> /bin/bash

root@e991d8ec09a7:/home/vmagent/app# python


>>> from scaper import Scrape
>>> import asyncio
>>> asyncio.run(Scrape().start())
Scrape has complete -- Entries: 268
>>>

I am wondering if it is even possible to run chromedriver on Cloud Run, and what limitations might be causing the chromedriver to fail. I have ran this code on App Engine just fine but I was hoping to port everything to Cloud Run though.

Here is the code I use for spawning the selenium web driver.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome('/home/vmagent/app/chromedriver', options=options)

Here you can see that my version of Chrome is supported by the chromedriver

root@2e53a4a78121:/home/vmagent/app# google-chrome --version
Google Chrome 76.0.3809.87
root@2e53a4a78121:/home/vmagent/app# ./chromedriver --version
ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809@{#864})

selenium==3.141.0

Any ideas on why my Cloud Run instance is having issues running a selenium webdriver?

来源:https://stackoverflow.com/questions/58780601/unable-to-run-selenium-chrome-driver-on-google-cloud-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!