반응형
셀레니움 에러 해결방법
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 를 붙여서 권한을 상승시켜주면 해결됩니다.
반응형
'다양한 TIP' 카테고리의 다른 글
google-chrome-stable 설치해보기(for selenium) (0) | 2023.11.10 |
---|---|
구글 애드센스 첫입금(국민은행 계좌번호 오입력으로 인한 오입금사태 해결) (2) | 2023.09.20 |
vim plugin ctrlp 설치방법(vimrc부터 Vundle.vim 설치까지) (0) | 2023.09.19 |
댓글