Luke Chalmers
Luke Chalmers

Reputation: 81

Selenium Wire Options in Python

So I using Selenium Wire in Python in order to browse a website and at present my code is failing with the following error

ERROR:ssl_client_socket_impl.cc(959)] handshake failed; returned -1, SSL error code 1, net_error -100'''

When I get this error Selenium seems to disconnect from the internet so subsequent clicks and interactions do not work. I had a look online and understand that I need to pass in the following arguments (Makes sense but correct me if I am wrong)

options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument('--ignore-ssl-errors').

I have the following code already which uses a proxy server but I am not sure how to pass the above argument into my current Selenium options with the proxy options already in place. I hope this makes sense?!

(I have changed my proxy server details for security reasons obvs).

Thanks!!!!!!

    import selenium

    from selenium.webdriver.common.keys import Keys

    from selenium.webdriver.common.by import By


    url = 'http://www.whatsmyipaddress.com'

    from seleniumwire import webdriver


    options = {
        'proxy': {
            'http': 'http://myusername:[email protected]:123456', 
            'https': 'http://myusername:[email protected]:123456',
            'no_proxy': 'localhost,127.0.0.1' # excludes
        }  
    }

    driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe", 
    seleniumwire_options=options)

    driver.get(url=url)

Upvotes: 8

Views: 38789

Answers (1)

tony stark
tony stark

Reputation: 171

You should use seleniumwire_options arg (of seleniumwire.webdriver.Chrome) for proxy options and optionsarg for the rest of your options.

Code example:

    from seleniumwire import webdriver

    # selenium-wire proxy settings
    # note: setting https:// for the 'http' key as well is not a mistake,
    # but a workaround to avoid `ValueError: 
    # Different settings for http and https proxy servers not supported`
    seleniumwire_options = {
            'proxy': {
                'https': 'https://myusername:[email protected]:123456', 
                'https': 'https://myusername:[email protected]:123456',
                'no_proxy': 'localhost,127.0.0.1' # excludes
            }  
        }
    
    # other Chrome options
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--ignore-certificate-errors-spki-list')
    chrome_options.add_argument('--ignore-ssl-errors')
    
    driver = webdriver.Chrome('chromedriver', 
                              options=chrome_options,
                              seleniumwire_options=seleniumwire_options)

Upvotes: 17

Related Questions