网络驱动程序错误"urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// o



我是python的新手,当我想运行以下简单的代码时,我得到了错误:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.whatsmyip.org")

错误:

Traceback (most recent call last):
File "C:UsersSaeedDesktopinsta botinstagram.py", line 3, in <module>
browser = webdriver.Firefox()
File "C:UsersSaeedAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 177, in __init__
executor = FirefoxRemoteConnection(
File "C:UsersSaeedAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriverfirefoxremote_connection.py", line 27, in __init__
RemoteConnection.__init__(self, remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
File "C:UsersSaeedAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriverremoteremote_connection.py", line 155, in __init__
self._conn = self._get_connection_manager()
File "C:UsersSaeedAppDataLocalProgramsPythonPython310libsite-packagesseleniumwebdriverremoteremote_connection.py", line 143, in _get_connection_manager
urllib3.ProxyManager(self._proxy_url, **pool_manager_init_args)
File "C:UsersSaeedAppDataLocalProgramsPythonPython310libsite-packagesurllib3poolmanager.py", line 480, in __init__
raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://

提前感谢您的指导。

当您的客户端代码(您的测试)试图向WebDriver服务发送命令时出现此错误。由于它是REST(通过http), Selenium采用在环境变量中定义的对应协议的代理:

def _get_proxy_url(self):
if self._url.startswith('https://'):
return os.environ.get('https_proxy', os.environ.get('HTTPS_PROXY'))
elif self._url.startswith('http://'):
return os.environ.get('http_proxy', os.environ.get('HTTP_PROXY'))

看起来分配给其中一个(或两个)变量的值不是一个正确的URL。

解决方案是:

  • 修改URL
  • 或在FirefoxOptions
  • 中切换ignore_local_proxy_environment_variables

相关内容