小编典典

尽管存在--ignore-certificate-errors,但ChromeDriver ERR_SSL_PROTOCOL_ERROR

selenium

我正在尝试使用带有selenium和ChromeDriver的本地主机(没有HTTPS)上的集成测试。

Chrome需要使用https证书,但是根据这个问题,我知道我可以使用arg来绕过它--ignore-certificate- errors

我也增加了自己的功能acceptInsecureCerts,因为这似乎是适当的做法(docs

chromedriver的响应仍然不是我所期望的:

该网站无法提供安全连接,应用发送的响应无效。ERR_SSL_PROTOCOL_ERROR

我的代码如下:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# make options (principally to ignore certificate)
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')

# add acceptInsecureCerts
capabilities = options.to_capabilities()
capabilities['acceptInsecureCerts'] = True

print(capabilities) # see below

driver = webdriver.Remote(
    command_executor=SELENIUM_HUB,
    desired_capabilities=capabilities
)
print(driver.__dict__) # see further below

app_login_url = 'http://app:8000/accounts/login/'

driver.get(app_login_url)

我的能力:

{'acceptInsecureCerts': True,
'browserName': 'chrome',
'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],
                        'extensions': []},
'platform': 'ANY',
'version': ''}

这是我的驱动程序信息,似乎只acceptInsecureCerts考虑了arg:

{'_file_detector': <selenium.webdriver.remote.file_detector.LocalFileDetector object at 0x7fb42bde10f0>,
'_is_remote': True,
'_mobile': <selenium.webdriver.remote.mobile.Mobile object at 0x7fb42bb5e400>,
'_switch_to': <selenium.webdriver.remote.switch_to.SwitchTo object at 0x7fb42bdd4898>,
'capabilities': {'acceptInsecureCerts': True,
                'acceptSslCerts': True,
                'applicationCacheEnabled': False,
                'browserConnectionEnabled': False,
                'browserName': 'chrome',
                'chrome': {'chromedriverVersion': '74.0.3729.6 '
                                                    '(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})',
                            'userDataDir': '/tmp/.com.google.Chrome.vc1ZvB'},
                'cssSelectorsEnabled': True,
                'databaseEnabled': False,
                'goog:chromeOptions': {'debuggerAddress': 'localhost:40815'},
                'handlesAlerts': True,
                'hasTouchScreen': False,
                'javascriptEnabled': True,
                'locationContextEnabled': True,
                'mobileEmulationEnabled': False,
                'nativeEvents': True,
                'networkConnectionEnabled': False,
                'pageLoadStrategy': 'normal',
                'platform': 'Linux',
                'proxy': {},
                'rotatable': False,
                'setWindowRect': True,
                'strictFileInteractability': False,
                'takesHeapSnapshot': True,
                'takesScreenshot': True,
                'timeouts': {'implicit': 0,
                            'pageLoad': 300000,
                            'script': 30000},
                'unexpectedAlertBehaviour': 'ignore',
                'version': '74.0.3729.169',
                'webStorageEnabled': True,
                'webdriver.remote.sessionid': '1cf77f237e966bac6ca15d4d9c107423'},
'command_executor': <selenium.webdriver.remote.remote_connection.RemoteConnection object at 0x7fb42be0cf98>,
'error_handler': <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7fb427d08a20>,
'session_id': '1cf77f237e966bac6ca15d4d9c107423',
'w3c': False}

为什么我仍然看到ERR_SSL_PROTOCOL_ERROR


阅读 1130

收藏
2020-06-26

共1个答案

小编典典

此错误消息…

This site can’t provide a secure connection app sent an invalid response. ERR_SSL_PROTOCOL_ERROR

…表示 ChromeDriver 无法启动/产生新的 WebBrowser, 即本地主机上的 Chrome浏览器 会话。

正如你所看到的这个问题,你对 本地主机(没有HTTPS)
按照此评论一眼罩的解决办法是增加argument
--allow-insecure-localhost 通过chromeOptions()如下:

'goog:chromeOptions': {'args': ['--allow-insecure-localhost'],
            'extensions': []}

但是你的主要问题似乎是与 能力 ,你必须设置platform为集合S ANY 如下:

{'acceptInsecureCerts': True,
'browserName': 'chrome',
'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],
            'extensions': []},
'platform': 'ANY',
'version': ''}

正如WebDriver-W3C Living DocumentplatformName
部分提到的那样,以下平台名称通常以易于理解的语义使用,并且在匹配功能时,通过将其作为已知操作系统的有效同义词来实现最大的互操作性:

Key         System
---         ------
"linux"     Any server or desktop system based upon the Linux kernel.
"mac"       Any version of Apple’s macOS.
"windows"   Any version of Microsoft Windows, including desktop and mobile versions.

注意 :此列表并不详尽。

从New Session返回功能时,返回更特定的platformName是有效的,从而允许用户正确标识WebDriver实现在其上运行的操作系统。

因此"platform":"ANY"与其 传递 期望的功能 对象, 不如说 是更具体的"platform":"linux"方法。


有关 ChromeDriverChromeSelenium Client 版本的更多信息将有助于我们以更好的方式分析问题。但是,根据
ChromeDriver的 历史记录,最近几个版本的 ChromeDriver 中解决了与 证书错误 处理相关的以下问题: __

  • 允许通过DevTools处理证书错误:由于无头chrome无法显示SSL证书错误的UI警告,因此发布了一个修复程序以将错误暴露为DevTools事件,并控制通过DevTools命令执行的操作。
  • 提供无头处理Chromedriver / Selenium中的证书错误的能力:以前,通过Chromium的UI版本(如)中的CLI开关控制的某些与安全相关的选项--ignore-certificate-errors忽略,只能通过devtools进行设置。因此,有必要certificateError在以浏览器为目标的DevTools客户端上覆盖和处理事件。一个补丁发布实施新DevTools方法的使用,以替代证书错误处理浏览器的宽这使得在无头模式忽略证书错误太多。
  • 通过DevTools进行全局证书错误处理:以前,DevTools允许处理单个目标/ WebContents的证书错误,但是当创建新目标(例如,单击target = _blank链接)时,通常无法足够快地发送Security.enable/ Security.setOverrideCertificateErrors命令在尝试导航之前。一个修复用简单的“忽略所有证书错误”模式发布,取而代之的是新的,而不是过时的旧覆盖命令setIgnoreCertificateErrors命令,它也暴露了在浏览器上的目标的安全域,以促进全球范围内应用该重写了整个浏览器。

结论

  • 确保添加了以下参数/功能:
    • --allow-insecure-localhost
    • acceptInsecureCerts
    • --ignore-certificate-errors
  • 使用时'chromedriverVersion': '74.0.3729.6',请确保您也正在使用'chrome': '74.0'(根据ChromeDriver v74.0.3729.6发行说明)
  • 确保您使用的是最新发布的 Selenium v​​3.141.59 客户端。
2020-06-26