python selenium解决handshake failed; returned -1, SSL error code 1, net_error -101问题

学习selenium过程中总会遇到各种各样的问题
今天后台一直循环运行RPA的时候,发现了输出了好多这样的error

解决方法:
这是由于不安全的地址错误,循环报错,导致程序终止。在配置chromedriver的时候在chrome_options中添加一个–ignore-certificate-errors参数,忽略掉证书错误,如下:

# 配置chromedriver
s = Service(executable_path='C:\Program Files\Google\Chrome\Application\chromedriver.exe')
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--ignore-certificate-errors')    # 忽略证书错误
driver = webdriver.Chrome(service=s, options=chrome_options)

还有一些其它莫名其妙的输出日志, 比如这两个:

DevTools listening on ws://127.0.0.1:49842/devtools/browser/6428a4e5-3d56-4b15-b894-795b1b4aaab0
[8132:7552:0518/093030.553:ERROR:device_event_log_impl.cc(214)] [09:30:30.553] Bluetooth: bluetooth_adapter_winrt.cc:1075 Getting Default Adapter failed.

不停的提示,虽然不影响程序的运行,可是看到这些乱七八糟的就烦… 搜了一下, 找到这两个输出的抑制方法:

# 配置chromedriver
s = Service(executable_path='C:\Program Files\Google\Chrome\Application\chromedriver.exe')
chrome_options = webdriver.ChromeOptions()
# 忽略证书错误
chrome_options.add_argument('--ignore-certificate-errors')
# 忽略 Bluetooth: bluetooth_adapter_winrt.cc:1075 Getting Default Adapter failed. 错误
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
# 忽略 DevTools listening on ws://127.0.0.1... 提示
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(service=s, executable_path='<path-to-chrome>', options=chrome_options)

然后我的小黑框就清爽了许多,看起来也舒服

记录备忘.

风影OvO

风影OvO, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA 4.0协议进行授权 | 转载请注明原文链接

3 Comments

  • 我的有这两个参数 还是报这样的错

    • @maryhu52 对于不同的浏览器需要添加不同的参数, 可以参考以下内容做一下尝试:

      1、对于Chrome,您需要添加 -ignore-certificate-errors 和-ignore-ssl-errors ChromeOptions()参数:

      options = webdriver.ChromeOptions()
       options.add_argument('-ignore-certificate-errors')
       options.add_argument('-ignore -ssl-errors')
       driver = webdriver.Chrome(chrome_options = options)

      2、对于Firefox,您需要将 accept_untrusted_certs 设置为True:

      profile = webdriver.FirefoxProfile()
       profile.accept_untrusted_certs = True 
       driver = webdriver.Firefox(firefox_profile = profile)

      3、对于Internet Explorer,您需要设置 acceptSslCerts 所需的功能:

      caps = webdriver.DesiredCapabilities.INTERNETEXPLORER
      caps['acceptInsecureCerts'] = True
      caps['acceptSslCerts'] = True
      driver = webdriver.Ie(capabilities = capabilities)
      • @风影OvO 太贊了,感謝博主,解決了項目上遇到的問題

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

相关推荐