Selenium proxy error using GeckoDriver when requesting localhost/session URL

Viewed 21

I try to setup a Selenium instance with the GeckoDriver (to target Firefox). I need to set a proxy for the connections. This is the following code I use to launch the instance and set the proxy:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service

DRIVER_PATH = 'C:/Users/xxxxx/drivers/geckodriver.exe'

proxies = {
    "proxyType": "MANUAL",
    "http": 'http://myproxy.local:5555',
    "https": 'http://myproxy.local:5555',
    "noProxy": ["localhost", "127.0.0.1"]
}
options = webdriver.FirefoxOptions()

driver = webdriver.Firefox(service=Service(DRIVER_PATH), options=options, proxy=proxies)

When I run the code, I receive an error from Selenium, indicating that he is trying to connect to a localhost session URL and that the proxy denied the access. This is normal, localhost URL should not be handled by proxies. But I do have specified a noProxy option to exclude localhost. But it looks like the "noProxy" directive is not taken into account. Any idea on where lies the problem?

And also, why is Selenium trying to connect to this local URL?

Thank you very much!

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    driver = webdriver.Firefox(service=Service(DRIVER_PATH), options=options, proxy=proxies)
  File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\firefox\webdriver.py", line 177, in __init__
    super().__init__(
  File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\remote\webdriver.py", line 270, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\remote\webdriver.py", line 363, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\remote\errorhandler.py", line 207, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta type="copyright" content="Copyright (C) 1996-2019 The Squid Software Foundation and contributors">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>
<style type="text/css"><!--


body
:lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; }
:lang(he) { direction: rtl; }
 --></style>
</head><body id=ERR_ACCESS_DENIED>
<div id="titles">
<h1>ERROR</h1>
<h2>The requested URL could not be retrieved</h2>
</div>
<hr>

<div id="content">
<p>The following error was encountered while trying to retrieve the URL: <a href="http://localhost:50693/session">http://localhost:50693/session</a></p>

<blockquote id="error">
<p><b>Access Denied.</b></p>
</blockquote>

<p>Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.</p>

<p>Your cache administrator is <a href="mailto:webmaster?subject=CacheErrorInfo%20-%20ERR_ACCESS_DENIED&amp;body=CacheHost%3A%20proxy%0D%0AErrPage%3A%20ERR_ACCESS_DENIED%0D%0AErr%3A%20%5Bnone%5D%0D%0ATimeStamp%3A%20Fri,%2023%20Sep%202022%2010%3A52%3A46%20GMT%0D%0A%0D%0AClientIP%3A%2010.45.180.20%0D%0A%0D%0AHTTP%20Request%3A%0D%0APOST%20%2Fsession%20HTTP%2F1.1%0AAccept-Encoding%3A%20identity%0D%0AContent-Length%3A%20169%0D%0AAccept%3A%20application%2Fjson%0D%0AContent-Type%3A%20application%2Fjson%3Bcharset%3DUTF-8%0D%0AUser-Agent%3A%20selenium%2F4.4.3%20(python%20windows)%0D%0AConnection%3A%20keep-alive%0D%0AHost%3A%20localhost%3A50693%0D%0A%0D%0A%0D%0A">webmaster</a>.</p>
<br>
</div>

<hr>
<div id="footer">
<p>Generated Fri, 23 Sep 2022 10:52:46 GMT by proxy (squid/4.10)</p>
<!-- ERR_ACCESS_DENIED -->
</div>
</body></html>
0 Answers
Related