Dwi Nissa A.
Dwi Nissa A.

Reputation: 43

Error When Rotating Proxy Selenium Webdriver Message: invalid argument: unrecognized capability: acceptSslCerts Stacktrace: GetHandleVerifier

Please help me to solve this error. I want to scraping using selenium webdriver and rotating proxy, but i don't know what is the correct configuration to seting proxy and got this error. How to do that?

Here is my code so far:

from selenium import webdriver
import time
import requests
from bs4 import BeautifulSoup

PATH = r'chromedriver.exe'

def listProxies():
    """Get List of Free Proxy."""
    r = requests.get('https://free-proxy-list.net/')
    soup = BeautifulSoup(r.content, 'html.parser')
    table = soup.find('tbody')
    
    proxies = []
    for row in table:
        if row.find_all('td')[4].text == 'elite proxy':
          proxy = ':'.join([row.find_all('td')[0].text, row.find_all('td')[1].text])
          proxies.append(proxy)
        else:
          pass
    return proxies
    
def getProxy(prox):
    proxy = {"http": f"http://{prox}",
             "https": f"http://{prox}"
            }
    return proxy
    
def getProx():
    """Choose and get available Proxy from list"""
    proxies = listProxies()
    for prox in proxies:
        # Free proxy (IP:PORT format from SSLProxies)
        proxy = getProxy(prox)
        try:
            print(f"trying proxy:{proxy}...")
            response = requests.get("http://httpbin.org/ip", proxies=proxy, timeout=5)
            if response.status_code == 200:
                print("Yay, its working! Proxy is working:", response.json()) # Should return the proxy's IP if working
                return prox
            else:
                print("Proxy failed, switching...") # Get a new one
            break
        except requests.exceptions.RequestException as e:
            print(f"Proxy failed: {e}. Trying another one")

def start_driver():
    """Starts Selenium WebDriver with a random proxy."""
    prox = getProx() # (Update regularly or use a free-proxy)
    proxy = getProxy(prox)
    webdriver.DesiredCapabilities.CHROME['proxy'] = {
        "httpProxy": prox,
        "ftpProxy": prox,
        "sslProxy": prox,
        "proxyType": "MANUAL",
    }
    webdriver.DesiredCapabilities.CHROME['acceptSslCerts']=True
    driver =webdriver.Chrome(service = webdriver.ChromeService(executable_path=PATH))
    return driver

My Running Code

"""Running Code"""
try:
    driver = start_driver()
    driver.get("'http://whatismyipaddress.com'")
except Exception as e:
    print(f"Proxy failed: {e}. Retrying with a new proxy...\n")
    time.sleep(3)  # Wait before retrying
print("Done.")

But It gives me error message:


    Message: invalid argument: unrecognized capability: acceptSslCerts Stacktrace:
    GetHandleVerifier [0x00007FF7F3396EE5+28773]
    (No symbol) [0x00007FF7F33025D0]
    (No symbol) [0x00007FF7F3198FAA]...etc

I just using free proxy.. is it still possible to do so? I also have update my Selenium to the newest version: 4.29.0, but it still gives me an error :(( really need some helps..

Thank you for your kind help, everyone!

Upvotes: 1

Views: 43

Answers (0)

Related Questions