【问题标题】:webdriver error "urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://"webdriver 错误“urllib3.exceptions.ProxySchemeUnknown:代理 URL 没有方案,应以 http:// 或 https:// 开头”
【发布时间】:2021-10-18 08:04:12
【问题描述】:

我是 python 新手,当我想运行以下简单代码时出现错误:

from selenium import webdriver

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

错误:

Traceback (most recent call last):
  File "C:\Users\Saeed\Desktop\insta bot\instagram.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 177, in __init__
    executor = FirefoxRemoteConnection(
  File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\firefox\remote_connection.py", line 27, in __init__
    RemoteConnection.__init__(self, remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
  File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 155, in __init__
    self._conn = self._get_connection_manager()
  File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 143, in _get_connection_manager
    urllib3.ProxyManager(self._proxy_url, **pool_manager_init_args)
  File "C:\Users\Saeed\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\poolmanager.py", line 480, in __init__
    raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://

提前感谢您的指导。

【问题讨论】:

  • 您使用的是哪个版本的 selenium?
  • @AlexeyR。硒 V 4.0.0

标签: python selenium selenium-webdriver proxy


【解决方案1】:

当您的客户端代码(您的测试)尝试向 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

【讨论】:

  • 我的问题通过将代码更改为:from selenium import webdriver from selenium.webdriver.firefox.options import Options opts = Options() opts.ignore_local_proxy_environment_variables() driver = webdriver.Firefox(options=opts) driver.get("https://stackoverflow.com/") 谢谢@AlexeyR
猜你喜欢
  • 1970-01-01
  • 2010-12-31
  • 2021-07-04
  • 1970-01-01
  • 2015-11-09
  • 2017-11-19
  • 2016-07-18
  • 1970-01-01
  • 2014-11-17
相关资源
最近更新 更多