在最后写一次 2023-08-09 11:29 采纳率: 40%
浏览 7
已结题

docker搭建的selenium/hub抛出: DevToolsActivePort file doesn't exist异常,如何解决?

docker搭建的selenium/hub抛出: DevToolsActivePort file doesn't exist异常

环境:

  • Ubuntu 22.04.2
  • docker版本:24.0.5
  • docker-compose版本: v2.20.2
  • python版本:3.10.12

docker-compose.yml文件如下

version: "3"
services:
  selenium-hub:
    image: selenium/hub:latest
    ports:
      - "8089:4444"
    environment:
      - GRID_MAX_SESSION=10
    networks:
      - grid

  chrome1:
    image: selenium/node-chrome:115.0.5790.110
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    shm_size: "2g"
    networks:
      - grid

  chrome2:
    image: selenium/node-chrome:115.0.5790.110
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    shm_size: "2g"
    networks:
      - grid

networks:
  grid:
    driver: bridge


执行的python脚本

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_argument(
    "User-Agent=Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36")
driver=webdriver.Remote("http://localhost:8089/wd/hub",options=chrome_options)
driver.set_page_load_timeout(10)
# driver.set_window_size(412, 892)
driver.maximize_window()

def selenium_get_text(url):
    try:
        driver.get(url)
    except TimeoutException:
        webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
    html = driver.page_source
    return html

if __name__ == '__main__':
    con = selenium_get_text("https://www.baidu.com/")
    print(con)
    driver.quit()

在python的报错日志如下

Traceback (most recent call last):
  File "/root/data/test.py", line 19, in <module>
    driver=webdriver.Remote("http://localhost:8089/wd/hub",options=chrome_options)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 290, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 345, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new session. java.util.concurrent.TimeoutException
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-73-generic', java.version: '11.0.20'
Driver info: driver.version: unknown
Host info: host: '98b7729a1b38', ip: '172.20.0.2'
Stacktrace:
    at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession (LocalDistributor.java:652)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession (LocalDistributor.java:565)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest (LocalDistributor.java:829)
    at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1 (LocalDistributor.java:785)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    at java.lang.Thread.run (Thread.java:829)

selenium/node-chrome下的异常

03:12:47.062 WARN [SeleniumManager.lambda$runCommand$1] - The chromedriver version (115.0.5790.102) detected in PATH at /usr/bin/chromedriver might not be compatible with the detected chrome version (115.0.5790.110); currently, chromedriver 115.0.5790.170 is recommended for chrome 115.*, so it is advised to delete the driver in PATH and retry
03:16:35.162 WARN [DriverServiceSessionFactory.apply] - Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: chrome not reachable
Host info: host: 'ccebdb1eec0e', ip: '172.20.0.4'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-73-generic', java.version: '11.0.20'
Driver info: driver.version: unknown
03:16:45.489 INFO [OsProcess.destroy] - Unable to drain process streams. Ignoring but the exception being swallowed follows.
org.apache.commons.exec.ExecuteException: The stop timeout of 2000 ms was exceeded (Exit value: -559038737)
        at org.apache.commons.exec.PumpStreamHandler.stopThread(PumpStreamHandler.java:295)
        at org.apache.commons.exec.PumpStreamHandler.stop(PumpStreamHandler.java:180)
        at org.openqa.selenium.os.OsProcess.destroy(OsProcess.java:144)
        at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:142)
        at org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:293)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:220)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:73)
        at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)
        at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:467)
        at org.openqa.selenium.grid.node.NewNodeSession.execute(NewNodeSession.java:50)
        at org.openqa.selenium.remote.http.Route$TemplatizedRoute.handle(Route.java:193)
        at org.openqa.selenium.remote.http.Route.execute(Route.java:69)
        at org.openqa.selenium.grid.security.RequiresSecretFilter.lambda$apply$0(RequiresSecretFilter.java:62)
        at org.openqa.selenium.remote.tracing.SpanWrappedHttpHandler.execute(SpanWrappedHttpHandler.java:91)
        at org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)
        at org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:347)
        at org.openqa.selenium.remote.http.Route.execute(Route.java:69)
        at org.openqa.selenium.grid.node.Node.execute(Node.java:262)
        at org.openqa.selenium.remote.http.Route$CombinedRoute.handle(Route.java:347)
        at org.openqa.selenium.remote.http.Route.execute(Route.java:69)
        at org.openqa.selenium.remote.AddWebDriverSpecHeaders.lambda$apply$0(AddWebDriverSpecHeaders.java:35)
        at org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44)
        at org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)
        at org.openqa.selenium.remote.ErrorFilter.lambda$apply$0(ErrorFilter.java:44)
        at org.openqa.selenium.remote.http.Filter$1.execute(Filter.java:63)
        at org.openqa.selenium.netty.server.SeleniumHandler.lambda$channelRead0$0(SeleniumHandler.java:44)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
03:16:45.498 ERROR [OsProcess.destroy] - Unable to kill process Process[pid=156, exitValue=0]
03:16:45.792 WARN [SeleniumSpanExporter$1.lambda$export$1] - Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: chrome not reachable

selenium/hub的异常

Host info: host: '98b7729a1b38', ip: '172.20.0.2'
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:652)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:565)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:829)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:785)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-73-generic', java.version: '11.0.20'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:391)
        at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
        at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)
        at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute(JdkHttpClient.java:347)
        at org.openqa.selenium.remote.tracing.TracedHttpClient.execute(TracedHttpClient.java:54)
        at org.openqa.selenium.grid.security.AddSecretFilter.lambda$apply$0(AddSecretFilter.java:40)
        at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:55)
        at org.openqa.selenium.grid.node.remote.RemoteNode.newSession(RemoteNode.java:129)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:648)
        ... 6 more
Caused by: java.util.concurrent.TimeoutException
        at java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1886)
        at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2021)
        at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:374)
        ... 14 more
  • 写回答

2条回答 默认 最新

  • IT工程师_二师兄 2023-08-09 12:11
    关注

    你把报错发给我看看吧

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月10日
  • 创建了问题 8月9日

悬赏问题

  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 游戏盾如何溯源服务器真实ip?
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥50 win10链接MySQL