Selenium ChromeDriver - driver.quit() 上的 HTTP 407
-
21-12-2019 - |
题
我在代理服务器后面。每当我打电话时,都会使用 Selenium 2.39、Python 2.7.6 和 ChromeDriver 2.9 .quit()
在 Chrome 实例上,我收到 HTTP 407 错误。使用FirefoxDriver时不会出现此类错误。
Traceback (most recent call last):
File "C:\Users\Tetrinity\Desktop\chrometest.py", line 7, in <module>
browser.quit()
File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 82, in quit
self.service.stop()
File "C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 97, in stop
url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 407: Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )
问题可以简化为以下脚本,我已将其另存为 chrometest.py
(如上面的堆栈跟踪所示):
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://www.google.co.uk")
browser.quit()
此脚本成功打开 Chrome 并导航到 Google。这 .quit()
然后导致上述崩溃,留下一个死亡的 ChromeDriver 实例。可能是什么原因造成的?我该如何预防?
研究已经找到了很多答案 不太相关, 使事情过于复杂 或者 声称这是一个已经解决的问题.
解决方案
由于我今天浪费了几个小时试图找到解决方案,因此我想我应该记录对我有用的内容。我通过打开 Internet 选项 > 连接 > LAN 设置 > 高级并插入 127.0.0.1
进入例外框。这样做之后, chrometest.py
已完成,没有错误,并且 ChromeDriver 窗口已成功关闭。
这个解决方案的功劳应该归功于提问者 这里. 。奇怪的是,这个问题从未出现在我的搜索中。当我快要完成这个问题的原始版本时,它出现在“类似问题”部分(看图!)。
其他提示
这是 Chrome 浏览器上的问题。以下步骤将为您提供解决方案。
1 |取消选中的复选框, By Proxy server for local address
2 |单击高级选项卡
3 |进入 127.0.0.1
在“例外”面板下
4 |单击确定
不隶属于 StackOverflow