Selenium Wire使用认证代理时抛出无效服务器规范错误
解决Selenium Wire配置认证代理的"无效服务器规范"错误
- 问题根源是代理URL的写法不符合Selenium Wire的要求,带身份验证的代理不能将用户名密码直接嵌入HTTP/HTTPS的URL字符串中,需要单独配置认证字段。
- 修改后的正确代码:
from proxy import getProxy from seleniumwire import webdriver import time username, password, ip, port = getProxy() options = { 'proxy': { 'http': f"http://{ip}:{port}", 'https': f"https://{ip}:{port}", 'no_proxy': 'localhost,127.0.0.1', 'username': username, 'password': password } } driver = webdriver.Chrome(executable_path='chromedriver.exe', seleniumwire_options=options) driver.get('http://whatismyipaddress.com') time.sleep(8) driver.quit()
- 关键改动:移除URL中的
{username}:{password}@部分,新增username和password两个独立配置项,让Selenium Wire能正确识别代理服务器的认证信息与地址规范。
内容的提问来源于stack exchange,提问作者Talha Ikram
相关产品推荐
相关产品推荐

