我是 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://
預先感謝您的指導。
uj5u.com熱心網友回復:
當您的客戶端代碼(您的測驗)嘗試向 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
- 或切換
ignore_local_proxy_environment_variables中FirefoxOptions
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/322596.html
