Python

[Python] 파이썬 DevToolsActivePort file doesn't exist 오류 해결

IT-PAPA 2023. 1. 12. 00:26
반응형

파이썬으로 구글 크롬 크롤링 최초 설치 및 사용시 발생하는 케이스 유형이다.

필자는 윈도우에서 비주얼코드를 통해 파이썬을 이용하여, 실행 시 아무런 문제가 발생하지 않았다.

하지만 우분투에서 실행시 아래와 같은 오류가 발생하였다.

ubuntu@ubuntu-web:~/python$ python3 crawling.py
Traceback (most recent call last):
  File "crawling.py", line 22, in <module>
    driver = webdriver.Chrome('./chromedriver', chrome_options=options)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/.local/lib/python3.6/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: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /home/ubuntu/python/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

 

해결 방안

chrome_options = Options()
chrome_options.add_argument("--headless") #크롬창을 숨긴채로 작업하기
chrome_options.add_argument("--no-sandbox") #리눅스 서버와 같이 GUI를 제공하지 않는 환경
chrome_options.add_argument("--single-process") #??
chrome_options.add_argument("--disable-dev-shm-usage") #/deb/shm 디렉토리를 사용하지 않는다는 의미이다. 이 디렉토리는 공유 메모리를 담당하는 부분

driver = webdriver.Chrome('/urs/bin/chromedriver', chrome_options=options)  # 크롬 드라이버로 크롬 켜기
728x90
반응형
LIST