简体   繁体   English

Docker Selenium:selenium.common.exceptions.WebDriverException:消息:服务chromedriver意外退出。 状态码为:127

[英]Docker Selenium: selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

I am using selenium's chromedriver in my python project. 我在python项目中使用了selenium的chromedriver。

I am building successfully my Dockerfile: 我正在成功构建我的Dockerfile:

FROM ubuntu:17.04
FROM selenium/standalone-chrome
FROM python:3.6
RUN apt update
RUN apt-get install -y libnss3 libgconf-2-4
ADD ./requirements.txt /tmp/requirements.txt
RUN python -m pip install -r /tmp/requirements.txt
ADD . /opt/example1/
# rights?
RUN chmod +x /opt/example1/assets/chromedriver
WORKDIR /opt/example1
CMD ["python","-u","program.py"]

But when I run my docker container I got following error: 但是当我运行Docker容器时,出现以下错误:

Traceback (most recent call last): File "program.py", line 8, in MdCrawler(MD_START_URL, "MobileDe").start() File "/opt/example1/mobile_de_crawler.py", line 17, in init self.web_driver_chrome = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH) File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init self.service.start() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start self.assert_process_still_running() File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running % (self.path, return_code) selenium.common.exceptions.WebDriverException: Message: Service /opt/example1/assets/chromedriver unexpectedly exited. 追溯(最近一次通话最后一次):在init self中的MdCrawler(MD_START_URL,“ MobileDe”)。start()文件“ /opt/example1/mobile_de_crawler.py”,第8行,文件“ program.py”。 (web_driver_chrome = webdriver.Chrome(executable_path = CHROME_DRIVER_PATH)文件“/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py”,线73,在初始化 self.service.start)在开始self.assert_process_still_running()中的文件“ /usr/local/lib/python3.6/site-packages/selenium/webdriver/common/service.py”第98行,文件“ /usr/local/lib/python3.6” /site-packages/selenium/webdriver/common/service.py“,第111行,在assert_process_still_running%(self.path,return_code)中selenium.common.exceptions.WebDriverException:消息:服务/ opt / example1 / assets / chromedriver意外退出。 Status code was: 127 状态码为:127

Anyone got an idea what could I do to prevent this error? 有人知道我该怎么做才能防止此错误? What is causing this crash? 是什么原因导致此崩溃?

Here is my initialization code where error occurs: 这是发生错误的初始化代码:

CHROME_DRIVER_PATH = os.path.abspath('assets/chromedriver')


class MdCrawler(Crawler):

def __init__(self, start_url, source):
    super().__init__(start_url, source)
    serialized_arr = self.read_data_from_json_file(JSON_FILE_PATH)
    self.sent_ids = [] if serialized_arr is None else serialized_arr
    >>> self.web_driver_chrome = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH)
    exit(1)

Edit 1: 编辑1:

I have edited Dockerfile (added ubuntu:17.04 and aptget libnss3 libgconf-2-4). 我已经编辑了Dockerfile(添加了ubuntu:17.04和aptget libnss3 libgconf-2-4)。 After building my docker image, I got different error: 构建我的docker映像后,出现了另一个错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform=Linux 4.9.125-linuxkit x86_64) selenium.common.exceptions.WebDriverException:消息:未知错误:找不到Chrome二进制文件(驱动程序信息:chromedriver = 2.45.615279(12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform = Linux 4.9.125-linuxkit x86_64)

Edit 2: 编辑2:

I have added 我已经添加了

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update
RUN apt-get install -y google-chrome-stable

To my Dockerfile, but new error is coming: 对于我的Dockerfile,但是新错误即将来临:

raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) (Driver info: chromedriver=2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform=Linux 4.9.125-linuxkit x86_64) 引发exception_class(消息,屏幕,堆栈跟踪)selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:异常退出(未知错误:DevToolsActivePort文件不存在)(该进程从Chrome位置/ usr /开始bin / google-chrome不再运行,因此ChromeDriver假定Chrome已崩溃。)(驱动程序信息:chromedriver = 2.45.615279(12b89733300bd268cff3b78fc76cb8f3a7cc44e5),platform = Linux 4.9.125-linuxkit x86_64)

Did you not forget to add headless mode ? 您是否忘记添加无头模式

chrome_options = Options()
chrome_options.add_argument("--headless")

My minimal test script for Selenium chromedriver inside my Docker container looks like this: 我在Docker容器中的Selenium chromedriver的最小测试脚本如下所示:

import selenium.webdriver

options = selenium.webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')

driver = selenium.webdriver.Chrome(chrome_options=options)
driver.get('https://www.python.org/')
print(driver.title)
driver.close()

So it looks like you're missing --headless and --no-sandbox arguments. 因此,似乎您缺少--headless--no-sandbox参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium.common.exceptions.WebDriverException:消息:服务 chromedriver 意外退出。 状态码是:1 - selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1 selenium.common.exceptions.WebDriverException:消息:chromedriver 意外退出。 状态码为:255 使用 Dockerfile 时 - selenium.common.exceptions.WebDriverException: Message: chromedriver unexpectedly exited. Status code was: 255 When using Dockerfile webDriverException“selenium.common.exceptions.WebDriverException:消息:Service./webdrivers/geckodriver 意外退出。状态代码为:1” - webDriverException "selenium.common.exceptions.WebDriverException: Message: Service ./webdrivers/geckodriver unexpectedly exited. Status code was: 1" selenium.common.exceptions.WebDriverException:消息:服务意外退出。 状态码为:3221225595 - selenium.common.exceptions.WebDriverException: Message: Service unexpectedly exited. Status code was: 3221225595 selenium.common.exceptions.WebDriverException:消息:Service.\geckodriver.exe 意外退出。 状态码为:3221225595 - selenium.common.exceptions.WebDriverException: Message: Service .\geckodriver.exe unexpectedly exited. Status code was: 3221225595 selenium.common.exceptions.WebDriverException:消息:服务geckodriver意外退出。 状态代码为:-11-如何解决? - selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: -11 - How to fix? selenium.common.exceptions.WebDriverException:消息:服务geckodriver意外退出。 状态码为:69 - selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 69 WebDriverException:消息:服务 chromedriver 意外退出。 状态代码为:127,在 Ubuntu 中使用 ChromeDriver 和 Selenium - WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127 with ChromeDriver and Selenium in Ubuntu selenium.common.exceptions.WebDriverException:消息:服务 chromedriver 意外退出 - selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited WebDriverException:消息:服务 chromedriver 意外退出。 状态代码为:127 - WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM