I'm using:
- Python 3.8
- Selenium 3.141.0
- Windows 10 (behind a proxy)
- Chrome:84.0.4147.105
- Chromedriver:84.0.4147.30
- Mac 10.15.6 (does not has a proxy)
Here is my code:
from selenium import webdriver
driver = webdriver.Chrome("D:/webdriver/chromedriver.exe")
driver.get("https://github.com")
driver.quit()
When executing driver.quit()
, the exception raise:
Traceback (most recent call last):
File "C:/Users/taiping/Desktop/data_test/selenium_test.py", line 5, in <module>
driver.quit()
File "D:\python3.8\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 158, in quit
self.service.stop()
File "D:\python3.8\lib\site-packages\selenium\webdriver\common\service.py", line 151, in stop
self.send_remote_shutdown_command()
File "D:\python3.8\lib\site-packages\selenium\webdriver\common\service.py", line 127, in send_remote_shutdown_command
url_request.urlopen("%s/shutdown" % self.service_url)
File "D:\python3.8\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "D:\python3.8\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "D:\python3.8\lib\urllib\request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "D:\python3.8\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "D:\python3.8\lib\urllib\request.py", line 1379, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "D:\python3.8\lib\urllib\request.py", line 1354, in do_open
r = h.getresponse()
File "D:\python3.8\lib\http\client.py", line 1332, in getresponse
response.begin()
File "D:\python3.8\lib\http\client.py", line 303, in begin
version, status, reason = self._read_status()
File "D:\python3.8\lib\http\client.py", line 272, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
But this code has no error on my Macbook. What's the problem?
Updated: 2020-08-05
I open the debugger and found that every HTTPConnection
object have been set the system wide http proxy. But I did not set any options explicitly in my code. And the driver.quit
method will send http://localhost:59717/shutdown to chrome to perform quit. So I guess the shutdown url is actually sent to the proxy server, not the local browser.
And I try to use fiddler to check the request informations. There is another problem that I can not decode the https requests because of some certificates configs. So I change the argument of driver.get()
to an internal web url of my company. The result is : If I close fiddler, RemoteDisconnected
error raise again. And if I open fiddler, all works.
What happened? I know fiddler set the proxy to 127.0.0.1:8888, so I think there could be something wrong with the proxy settings. But I can not fix it. I guess the chrome use the system proxy so the github home page could open correctly, but when send shutdown url to chrome, the request object should not use the system proxy, but it does.
Am I right? And how to fix this problem?