Selenium ChromeDriver - 关于driver.quit()的HTTP 407

时间:2014-02-25 15:05:56

标签: python selenium selenium-webdriver selenium-chromedriver

我在代理服务器后面。使用Selenium 2.39,Python 2.7.6和ChromeDriver 2.9,每当我在Chrome实例上调用.quit()时,都会收到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实例。可能导致这种情况的原因,我该如何预防?

研究提出了许多aren't quite relevantovercomplicate thingsclaim it's an issue that was already fixed的答案。

2 个答案:

答案 0 :(得分:3)

由于我今天浪费了几个小时试图找到解决方案,我想我会记录哪些对我有用。我通过打开Internet选项&gt;解决了这个问题。连接&gt; LAN设置&gt;高级并将127.0.0.1插入“例外”框。完成此操作后,chrometest.py完成且没有错误,ChromeDriver窗口已成功关闭。

此解决方案应归功于提问者here。奇怪的是,这个问题从未出现在我的搜索中。当我快要输入这个问题的原始版本时,它出现在“类似问题”部分中(如图!)。

答案 1 :(得分:1)

这是Chrome浏览器上的一个问题。以下步骤将为您提供修复。

1 |取消选中复选框By Proxy server for local address

enter image description here

2 |单击“高级选项卡”

enter image description here

3 |在“例外”面板

下输入127.0.0.1

4 |点击确定