Open QuintinTao opened 1 month ago
总结 手动下载chrome内核
从错误信息来看,Selenium 试图自动下载适用于 Chrome 的 WebDriver,但遇到了网络问题。具体来说,它无法访问 https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
来获取最新的 ChromeDriver 下载链接。这可能是由于网络连接问题、防火墙设置或代理配置阻止了请求。
要解决这个问题,你可以尝试以下几种方法:
手动下载 ChromeDriver:
将下载好的 ChromeDriver 放置在一个你知道的位置,然后在创建 WebDriver 实例时通过 executable_path
参数指定它的路径。例如:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(executable_path='/path/to/chromedriver')
driver = webdriver.Chrome(service=service, options=options)
检查网络连接和防火墙设置:
webdriver.ChromeOptions()
添加代理设置。使用 Selenium Manager 的替代方案:
如果你不想手动处理 WebDriver 的下载和更新,可以考虑使用第三方工具如 WebDriverManager for Python,它可以帮助自动化这个过程。安装后,可以这样使用:
pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
确保正确的浏览器版本:
查看 Selenium 文档:
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
) 可能会有更多针对此类问题的建议和解决方案。请根据你的具体情况选择合适的解决方法。如果这些步骤不能解决问题,请提供更多的上下文信息以便进一步诊断。
2024-10-17 17:29:47 - /data/digital_human_video_player-main/api_server.py[line:40] - INFO: static_folder=/data/digital_human_video_player-main/static INFO: Started server process [6674] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:8091 (Press CTRL+C to quit) 2024-10-17 17:29:47 - /data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py[line:138] - WARNING: Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json) Exception in thread Thread-1: Traceback (most recent call last): File "/data/miniconda/envs/player/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/data/digital_human_video_player-main/api_server.py", line 334, in run self._target(self._stop_event) File "/data/digital_human_video_player-main/api_server.py", line 313, in start_browser driver = webdriver.Chrome(options=options) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in init super().init( File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in init super().init(command_executor=executor, options=options) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in init self.start_session(capabilities) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session response = self.execute(Command.NEW_SESSION, caps)["value"] File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute self.error_handler.check_response(response) File "/data/miniconda/envs/player/lib/python3.10/site-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 /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace:
我把driver 手动安装了。ubuntu 环境。报这个。貌似服务也没起来
2024-10-17 17:29:47 - /data/digital_human_video_player-main/api_server.py[line:40] - INFO: static_folder=/data/digital_human_video_player-main/static INFO: Started server process [6674] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:8091 (Press CTRL+C to quit) 2024-10-17 17:29:47 - /data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py[line:138] - WARNING: Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json) Exception in thread Thread-1: Traceback (most recent call last): File "/data/miniconda/envs/player/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/data/digital_human_video_player-main/api_server.py", line 334, in run self._target(self._stop_event) File "/data/digital_human_video_player-main/api_server.py", line 313, in start_browser driver = webdriver.Chrome(options=options) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in init super().init( File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in init super().init(command_executor=executor, options=options) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in init self.start_session(capabilities) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session response = self.execute(Command.NEW_SESSION, caps)["value"] File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute self.error_handler.check_response(response) File "/data/miniconda/envs/player/lib/python3.10/site-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 /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace:
0 0x55984bed00aa
1 0x55984b9e71a0
2 0x55984ba1cfaa
3 0x55984ba18885
4 0x55984ba63ec6
5 0x55984ba63516
6 0x55984ba57b23
7 0x55984ba26990
8 0x55984ba2796e
9 0x55984be9c16b
10 0x55984be9ff68
11 0x55984be8964c
12 0x55984bea0ae7
13 0x55984be6e4af
14 0x55984bebe4f8
15 0x55984bebe6c0
16 0x55984becef26
17 0x7f9a0fb6c609 start_thread
似曾相识,不过忘记怎么搞得了。
好像还是内核问题,具体想不起来了。得查查资料
OK 大佬慢慢想
OK 大佬慢慢想
已经失忆了,剩下的路 得靠自己了
INFO: Uvicorn running on http://127.0.0.1:8091 (Press CTRL+C to quit) Exception in thread Thread-1: Traceback (most recent call last): File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py", line 67, in _binary_paths output = SeleniumManager().binary_paths(self._to_args()) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py", line 55, in binary_paths return self._run(args) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py", line 129, in _run raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: /data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/linux/selenium-manager --browser chrome --language-binding python --output json; code: 65 {'code': 65, 'message': 'error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json)', 'driver_path': '', 'browser_path': ''}
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/data/miniconda/envs/player/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/data/digital_human_video_player-main/api_server.py", line 333, in run self._target(self._stop_event) File "/data/digital_human_video_player-main/api_server.py", line 313, in start_browser driver = webdriver.Chrome(options=options) File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in init super().init( File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 50, in init if finder.get_browser_path(): File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py", line 47, in get_browser_path return self._binary_paths()["browser_path"] File "/data/miniconda/envs/player/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py", line 78, in _binary_paths raise NoSuchDriverException(msg) from err selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location