본문 바로가기
다양한 TIP

셀레니움 에러 session not created: DevToolsActivePort file doesn't exist, chrome not reachable 문제 해결

by 유기농프로그래밍 2023. 11. 7.
반응형

셀레니움 에러 해결방법

session not created: DevToolsActivePort file doesn't exist

  File "/home/sample/selenium_test.py", line 18, in get_url
    driver = webdriver.Chrome(service=service, options=opt)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/chromium/webdriver.py", line 56, in __init__
    super().__init__(
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

위의 에러에서의 핵심은 DevToolsActivePort 입니다. 해결방법은 아래와 같이 코드를 수정하면 됩니다.

    service = Service(executable_path=r'./chromedriver')
    opt = webdriver.ChromeOptions()
    opt.add_argument('--headless')
    opt.add_argument('--no-sandbox')
    driver = webdriver.Chrome(service=service, options=opt)

꼭 필요한건 --headless와 --no-sandbox 라고 보면 됩니다.

 

chrome not reachable

  File "/home/sample/selenium_test.py", line 19, in get_url
    driver = webdriver.Chrome(service=service, options=opt)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/chromium/webdriver.py", line 56, in __init__
    super().__init__(
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
  (chrome not reachable)
  (The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

DevToolsActivePort  문제를 해결 한 후에 위와 같은 문제가 다시 생겼습니다.

결론적으로 이 문제는 권한 문제입니다.

Chrome을 실행을 하는데 권한이 없어서 실행을 못한 것입니다.

 

간단하게 실행시 sudo 를 붙여서 권한을 상승시켜주면 해결됩니다.

반응형

댓글