ERROR:ssl_client_socket_openssl.cc(1158)] handshake failed with ChromeDriver Chrome browser and Selenium
Asked Answered
B

6

32

When running my python selenium script with Chrome driver I get about three of the below error messages every time a page loads even though everything works fine. Is there a way to suppress these messages?

[24412:18772:0617/090708:ERROR:ssl_client_socket_openssl.cc(1158)] handshake failed; returned -1, SSL error code 1, net_error -100

Biotype answered 17/6, 2016 at 14:9 Comment(2)
This could be a sign that the website requires a certificate which isn't in the certificate store of your web browser. SSL has this certificate exchange handshake protocol that must pass before going any farther.Waste
You can hide notifications of these errors as described in these answers.Guillerminaguillermo
C
42

You get this error when the browser asks you to accept the certificate from a website. You can set to ignore these errors by default in order avoid these errors.

For Chrome, you need to add --ignore-certificate-errors and --ignore-ssl-errors ChromeOptions() argument:

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

For the Firefox, you need to set accept_untrusted_certs FirefoxProfile() option to True:

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

For the Internet Explorer, you need to set acceptSslCerts desired capability:

capabilities = webdriver.DesiredCapabilities().INTERNETEXPLORER
capabilities['acceptSslCerts'] = True
driver = webdriver.Ie(capabilities=capabilities)
Conway answered 20/2, 2017 at 8:59 Comment(3)
Is this still up-to-date? I'm trying the solution but still error is still coming through...Rice
What does 1158 mean in ssl_client_socket_openssl.cc(1158)? Is that the line number? I get the same error but instead of 1158 it's 968. Also, none of the available solutions on SO work for me.Woodford
nah that doesn't work for Chrome anywayCurettage
O
7

This error message...

[ERROR:ssl_client_socket_openssl.cc(855)] handshake failed; returned -1, SSL error code 1, net_error -100

...implies that the handshake failed between ChromeDriver and Chrome Browser failed at some point.

Root Cause Analysis

This error is generated due to net::SSLClientSocketImpl::DoHandshake and net::SSLClientSocketImpl implemented in ssl_client_socket_impl.cc net::SSLClientSocketImpl::DoHandshake as follows:

int SSLClientSocketImpl::DoHandshake() {
  crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
  int rv = SSL_do_handshake(ssl_.get());
  int net_error = OK;
  if (rv <= 0) {
    int ssl_error = SSL_get_error(ssl_.get(), rv);
    if (ssl_error == SSL_ERROR_WANT_CHANNEL_ID_LOOKUP) {
      // The server supports channel ID. Stop to look one up before returning to
      // the handshake.
      next_handshake_state_ = STATE_CHANNEL_ID_LOOKUP;
      return OK;
    }
    if (ssl_error == SSL_ERROR_WANT_X509_LOOKUP &&
    !ssl_config_.send_client_cert) {
      return ERR_SSL_CLIENT_AUTH_CERT_NEEDED;
    }
    if (ssl_error == SSL_ERROR_WANT_PRIVATE_KEY_OPERATION) {
      DCHECK(ssl_config_.client_private_key);
      DCHECK_NE(kSSLClientSocketNoPendingResult, signature_result_);
      next_handshake_state_ = STATE_HANDSHAKE;
      return ERR_IO_PENDING;
    }
    OpenSSLErrorInfo error_info;
    net_error = MapLastOpenSSLError(ssl_error, err_tracer, &error_info);
    if (net_error == ERR_IO_PENDING) {
      // If not done, stay in this state
      next_handshake_state_ = STATE_HANDSHAKE;
      return ERR_IO_PENDING;
    }
    LOG(ERROR) << "handshake failed; returned " << rv << ", SSL error code "
           << ssl_error << ", net_error " << net_error;
    net_log_.AddEvent(
    NetLogEventType::SSL_HANDSHAKE_ERROR,
    CreateNetLogOpenSSLErrorCallback(net_error, ssl_error, error_info));
  }
  next_handshake_state_ = STATE_HANDSHAKE_COMPLETE;
  return net_error;
}

As per ERROR:ssl_client_socket_openssl.cc handshake failed the main issue is the failure of handshake when ChromeDriver handshakes with SSL pages in Chrome. Though Chromium team conducts test for SSL handshake through net_unittests, content_tests, and browser_tests but were not exhaustive. Some usecases are left out relying on the upstream tests.

Conclusion

This error won't interupt the execution of your Test Suite and you can ignore this issue for the time being till it is fixed by the Chromium Team.

Oreste answered 17/12, 2018 at 5:26 Comment(0)
P
0

For me it got resolved after writing code as below in chrome options, change from above answer was to include spki-list.

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument('--ignore-ssl-errors')
driver = webdriver.Chrome(chrome_options=options)
Phaeton answered 8/6, 2017 at 14:5 Comment(1)
Nope doesn't change a thingCurettage
J
0

For anyone running into this issue with Laravel and its Dusk browser testing suite, this is fixed by editing tests/DuskTestCase.php to add the --ignore-certificate-errors command-line switch:

   $options = (new ChromeOptions)->addArguments(collect([
       '--window-size=1920,1080',
       "--ignore-certificate-errors",
   ])->unless($this->hasHeadlessDisabled(), function ($items) {
         return $items->merge([
          '--disable-gpu',
          '--headless',
      ]);
   })->all());
Josephinajosephine answered 4/3, 2023 at 0:26 Comment(0)
J
-2

I was facing the same problem. The problem was I did set webdriver.chrome.driver system property to chrome.exe. But one should download chromedriver.exe and set the file path as a value to webdriver.chrome.driver system property.

Once this is set, everything started working fine.

Janellajanelle answered 9/3, 2017 at 9:37 Comment(2)
I'm sorry, could you elaborate how to do this, I'm not sure I followAnnmarie
I downvoted this answer, because it does not provide enough specifics to be useful. Please provide specific code example that you used to solve the problem. I will then upvote your answer.Heterocyclic
H
-2

ssl error means that the certificate is wrong and you should not allow execution or communication with a web address that is using a wrong ssl certificate. allow means that you accept the communication with a bogus or thief address and what ever comes when you communicate with them. So it is not browser problem or something that you should fix by reprogramming your browser to allow failed ssl certificates.

Hegumen answered 16/6, 2020 at 20:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.