如何解决Airflow Docker中ChromeDriverManager安装时的报错问题
解决
AttributeError: 'NoneType' object has no attribute 'split'报错 问题根源
这个错误是因为你的Airflow Docker容器里没有安装Google Chrome浏览器,导致webdriver-manager无法检测到本地Chrome的版本号,返回了None,后续代码尝试对None执行split()操作就抛出了异常。
解决方案
1. 在Docker镜像中安装Google Chrome
如果你的Docker基础镜像是Debian/Ubuntu系(比如Airflow官方镜像),在docker.yaml或对应的Dockerfile中添加Chrome安装步骤:
RUN apt-get update && apt-get install -y wget gnupg2 RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list RUN apt-get update && apt-get install -y google-chrome-stable
2. 清理冲突依赖包
你安装了多个功能重叠的chromedriver管理包(chromedriver_autoinstaller、chromedriver-py、chromedriver等),这些会和webdriver-manager产生冲突。修改docker.yaml,只保留必要的两个包:
# 仅保留以下PYPI包 - selenium - webdriver-manager
3. 优化代码确保Chrome路径正确
在代码中指定Chrome的安装路径(默认路径通常是/usr/bin/google-chrome-stable),避免路径检测失败:
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service as ChromeService chrome_options = webdriver.ChromeOptions() # 指定Chrome二进制文件路径 chrome_options.binary_location = "/usr/bin/google-chrome-stable" chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--download-path=/opt/airflow') chrome_options.add_argument('--no-gpu') chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--dns-prefetch-disable') chrome_service = ChromeService(ChromeDriverManager().install()) driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
4. 备选方案:手动指定chromedriver版本
如果自动检测还是有问题,可以直接指定与Chrome版本匹配的chromedriver版本号,比如:
# 替换为你安装的Chrome对应的版本号 chrome_service = ChromeService(ChromeDriverManager(version="114.0.5735.90").install())
内容的提问来源于stack exchange,提问作者Muthu lakshmi
相关产品推荐
相关产品推荐

