使用Appium执行Python自动化脚本时遇AttributeError报错求助
Appium Python脚本执行报错:AttributeError: 'AppiumConnection' object has no attribute '_ca_certs'
错误日志
Traceback (most recent call last): 文件 "E:\Projects\Python\Indee\pythonProject\TestCases\testCase1.py",第31行 driver = webdriver.Remote(url, options=AppiumOptions().load_capabilities(cap)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件 "E:\Projects\Python\Indee\pythonProject.venv\Lib\site-packages\appium\webdriver\webdriver.py",第227行,在 __init__中 command_executor = AppiumConnection(command_executor, keep_alive=keep_alive) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件 "E:\Projects\Python\Indee\pythonProject.venv\Lib\site-packages\appium\webdriver\appium_connection.py",第43行,在 __init__中 super().__init__(remote_server_addr, keep_alive=keep_alive, ignore_proxy=ignore_proxy) 文件 "E:\Projects\Python\Indee\pythonProject.venv\Lib\site-packages\selenium\webdriver\remote\remote_connection.py",第340行,在 __init__中 self._conn = self._get_connection_manager() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件 "E:\Projects\Python\Indee\pythonProject.venv\Lib\site-packages\appium\webdriver\appium_connection.py",第49行,在 _get_connection_manager中 if self._ca_certs: ^^^^^^^^^^^^^^ AttributeError: 'AppiumConnection' object has no attribute '_ca_certs' 进程结束,退出代码1
运行代码
import time from typing import Dict, Any from wsgiref.util import application_uri from appium import webdriver from appium.options.common import AppiumOptions from appium.webdriver.common.appiumby import AppiumBy from appium.webdriver.appium_service import AppiumService cap:Dict[str, Any]={ 'platformname':'Android', 'automationName':'uiautomator2', 'deviceName':'Android', 'appPackage':'com.android.settings', 'appActivity':'.Settings', 'language':'en', 'locale':'US' } url = 'http//localhost:4723' # app = 'E:\\Projects\\Python\\Indee\\pythonProject\\resources\\hfiPevjjJ1DgrIGU5G3n.apk' # appium_service = AppiumService() # appium_service.start() driver = webdriver.Remote(url, options=AppiumOptions().load_capabilities(cap)) print("Running") # appium_service.stop()
解决步骤
- 修复版本兼容性问题:该报错核心原因是Appium-Python-Client与Selenium版本不匹配。执行以下命令卸载现有版本并安装兼容组合:
pip uninstall selenium appium-python-client -y pip install selenium==4.10.0 appium-python-client==2.11.0 - 修正Appium服务地址:代码中
url缺少冒号且未指定默认路径,改为:url = 'http://localhost:4723/wd/hub' - 确保Appium服务已启动:取消代码中AppiumService相关注释,或者手动在终端执行
appium命令启动服务。 - 修正Capability键名大小写:将
platformname改为platformName(Appium对Capability键名大小写敏感):cap:Dict[str, Any]={ 'platformName':'Android', # 其余配置保持不变 }
内容的提问来源于stack exchange,提问作者InfiniteForLoop
相关产品推荐
相关产品推荐

