I'm new to python, when I want to run following simple code I got error:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.whatsmyip.org")
error:
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://
Thank you in advance for your guidance.
CodePudding user response:
This error appears when your client code (your test) attempts to send a command to a WebDriver service. Since it is REST (over http) Selenium takes the proxy that is defined in environment variable for corresponding protocol:
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'))
Looks like the value that is assigned to one of (or both) those vars is not a proper URL.
The solution would be:
- either to fix the URL
- or to toggle
ignore_local_proxy_environment_variables
inFirefoxOptions