ChromeDriver ERR_SSL_PROTOCOL_ERROR 尽管 --ignore-certificate-errors

ChromeDriver ERR_SSL_PROTOCOL_ERROR despite --ignore-certificate-errors(ChromeDriver ERR_SSL_PROTOCOL_ERROR 尽管 --ignore-certificate-errors)

本文介绍了ChromeDriver ERR_SSL_PROTOCOL_ERROR 尽管 --ignore-certificate-errors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 selenium 和 ChromeDriver 在本地主机(没有 HTTPS)上运行集成测试.

Chrome 需要 https 证书,但从 this 问题中我了解到我可以使用 arg --ignore-certificate-errors

来规避这个问题

我还增加了我的能力 acceptInsecureCerts,因为这似乎是适当的行动方案(docs)

chromedriver 的反应还是出乎我的意料:

<块引用>

此网站无法提供安全连接 应用发送了无效响应.ERR_SSL_PROTOCOL_ERROR

我的代码如下:

从 selenium 导入 webdriver从 selenium.webdriver.chrome.options 导入选项# 制作选项(主要是忽略证书)选项 = webdriver.ChromeOptions()options.add_argument('--ignore-certificate-errors')# 添加acceptInsecureCerts能力 = options.to_capabilities()能力['acceptInsecureCerts'] = Trueprint(capabilities) # 见下文驱动程序 = webdriver.Remote(command_executor=SELENIUM_HUB,所需的能力=能力)print(driver.__dict__) # 见下文app_login_url = 'http://app:8000/accounts/login/'driver.get(app_login_url)

我的能力:

{'acceptInsecureCerts': True,浏览器名称":铬",'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],'扩展':[]},平台":任何",'版本': ''}

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

{'_file_detector': <selenium.webdriver.remote.file_detector.LocalFileDetector object at 0x7fb42bde10f0>,'_is_remote':是的,'_mobile': <selenium.webdriver.remote.mobile.Mobile 对象在 0x7fb42bb5e400>,'_switch_to': <selenium.webdriver.remote.switch_to.SwitchTo 对象在 0x7fb42bdd4898>,'功能':{'acceptInsecureCerts':真,'acceptSslCerts':是的,'applicationCacheEnabled':假,'browserConnectionEnabled':假,浏览器名称":铬",'chrome': {'chromedriverVersion': '74.0.3729.6''(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})','userDataDir': '/tmp/.com.google.Chrome.vc1ZvB'},'cssSelectorsEnabled':真,'databaseEnabled':假,'goog:chromeOptions': {'debuggerAddress': 'localhost:40815'},'handlesAlerts':是的,'hasTouchScreen':错误,'javascriptEnabled':是的,'locationContextEnabled':真,'mobileEmulationEnabled':假,'nativeEvents':是的,'networkConnectionEnabled':假,'pageLoadStrategy': '正常',平台":Linux",'代理人': {},可旋转":错误,'setWindowRect':真,'strictFileInteractability':假,'takesHeapSnapshot':是的,'takesScreenshot':是的,'超时':{'隐式':0,页面加载":300000,'脚本': 30000},'unexpectedAlertBehaviour': '忽略','版本': '74.0.3729.169','webStorageEnabled':真,'webdriver.remote.sessionid': '1cf77f237e966bac6ca15d4d9c107423'},'command_executor': <selenium.webdriver.remote.remote_connection.RemoteConnection 对象在 0x7fb42be0cf98>,'error_handler': <selenium.webdriver.remote.errorhandler.ErrorHandler 对象在 0x7fb427d08a20>,'session_id': '1cf77f237e966bac6ca15d4d9c107423','w3c':错误}

为什么我仍然看到 ERR_SSL_PROTOCOL_ERROR?

解决方案

这个错误信息...

此站点无法提供安全连接应用程序发送了无效响应.ERR_SSL_PROTOCOL_ERROR

...暗示 ChromeDriver 无法在您的本地主机上启动/生成新的 WebBrowserChrome 浏览器 会话.p>

根据 this comment 一个盲目的解决方案是添加 argument --allow-insecure-localhost通过chromeOptions()如下:

'goog:chromeOptions': {'args': ['--allow-insecure-localhost'],扩展":[]}

<小时>

但是,您的主要问题似乎在于您设置 platformcapabilities 被设置为 ANY如下:

{'acceptInsecureCerts': True,浏览器名称":铬",'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],'扩展':[]},平台":任何",'版本': ''}

根据 WebDriver - W3C Living Document platformName 部分提到,以下平台名称是常用的,具有易于理解的语义,并且在匹配功能时,可以通过将它们视为知名操作系统的有效同义词来实现最大的互操作性:

钥匙系统--- ------linux" 任何基于 Linux 内核的服务器或桌面系统."mac" Apple macOS 的任何版本.windows" Microsoft Windows 的任何版本,包括桌面版和移动版.

注意:此列表并不详尽.

从新会话返回功能时,返回更具体的平台名称是有效的,允许用户正确识别运行 WebDriver 实现的操作系统.

因此,不是在 desiredCapabilities 对象中传递 "platform":"ANY",而是使用更具体的 "platform":"linux"将是更可取的方法.

<块引用>

您可以在 带有参数的 http POST 到/session 引发的 curl 错误:{desiredCapabilities":{browserName":chrome",platform":ANY" with Selenium 和 PHPUnit

<小时>

更多关于 ChromeDriverChromeSelenium Client vrsion 的信息将有助于我们以更好的方式分析问题.然而,根据 ChromeDriver 的历史记录,以下与处理 证书错误 相关的问题已在 ChromeDriver 的最后几个版本中得到解决:

  • 允许通过 DevTools 处理证书错误:作为 headlesschrome 无法针对 SSL 证书错误显示 UI 警告 修复 已发布以公开错误作为 DevTools 事件并通过 DevTools 命令控制要采取的操作.
  • 提供在 Chromedriver/Selenium for headless 中处理证书错误的能力:之前通过 CLI 开关控制的某些 安全相关选项Chromium 的 UI 版本(如 --ignore-certificate-errors)被静默忽略,只能通过 devtools 设置.因此有必要在浏览器目标 DevTools 客户端上覆盖和处理 certificateError 事件.修复已发布,实现了使用新的 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 客户端.

I'm trying to run integration tests on a local host (with no HTTPS) using selenium with ChromeDriver.

Chrome requires an https certificate, but from this question i understand that i can circumvent this using the arg --ignore-certificate-errors

I have also added to my capabilities acceptInsecureCerts, as this seems like the appropriate course of action (docs)

The response from the chromedriver is still not what I was expecting:

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

My code is below:

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)

My capabilities:

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

Here is my driver info, it looks like only the acceptInsecureCerts arg has been taken into account:

{'_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}

Why am i still seeing the ERR_SSL_PROTOCOL_ERROR ?

解决方案

This error message...

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

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session on your localhost.

As you are seeing this issue on your local host (with no HTTPS) as per this comment a blind fold solution would be to add the argument --allow-insecure-localhost through chromeOptions() as follows:

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


However your main issue seems to be with the capabilities where you have set platform being set s ANY as follows:

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

As per WebDriver - W3C Living Document the platformName section mentions, the following platform names are in common usage with well-understood semantics and, when matching capabilities, greatest interoperability can be achieved by honoring them as valid synonyms for well-known Operating Systems:

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.

Note:This list is not exhaustive.

When returning capabilities from New Session, it is valid to return a more specific platformName, allowing users to correctly identify the Operating System the WebDriver implementation is running on.

So instead of passing "platform":"ANY" within the desiredCapabilities object, a more specific "platform":"linux" will be more desirable approach.

You can find a relevant and related discussion in Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY" with Selenium and PHPUnit


Some more information about the ChromeDriver, Chrome and Selenium Client vrsion would have helped us to analyze the issue in a better way. However as per ChromeDriver history the following issues related to handling of certificate errors were addressed in the last few releases of ChromeDriver:

  • Allow handling certificate errors via DevTools: As the headless chrome cannot show a UI warning for SSL certificate errors a fix was released to expose the errors as DevTools events and control the action to take through a DevTools command.
  • Provide ability to handle certificate errors in Chromedriver/Selenium for headless: Earlier certain security related options that was controlled via CLI switches in the UI version of Chromium (like --ignore-certificate-errors) were silently ignored and can only be set via devtools. So it was necessary to override and handle certificateError events on the browser-target DevTools client. A fix was released implementing the usage of the new DevTools method to override certificate error handling browser-wide which allowed ignoring certificate errors in headless mode too.
  • Global certificate error handling via DevTools: Previously DevTools allowed handling certificate errors for individual targets / WebContents, but when a new target was created (e.g. clicking on a target=_blank link), it was not often not possible to send the Security.enable / Security.setOverrideCertificateErrors commands quickly enough before a navigation is attempted. A fix was published with a simpler "ignore all cert errors" mode instead deprecated the old override command in favor of a new setIgnoreCertificateErrors command which also exposes the Security domain on the browser target to facilitate applying this override globally for the whole browser.

Conclusion

  • Ensure that the following arguments/capabilities are added:
    • --allow-insecure-localhost
    • acceptInsecureCerts
    • --ignore-certificate-errors
  • As you are using 'chromedriverVersion': '74.0.3729.6' ensure that you are also using 'chrome': '74.0' (as per ChromeDriver v74.0.3729.6 Release Notes)
  • Ensure that you are using the latest released Selenium v3.141.59 clients.

这篇关于ChromeDriver ERR_SSL_PROTOCOL_ERROR 尽管 --ignore-certificate-errors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ChromeDriver ERR_SSL_PROTOCOL_ERROR 尽管 --ignore-certificate-errors

基础教程推荐