【发布时间】:2018-12-20 07:30:26
【问题描述】:
尝试通过
运行 selenium for chrome/usr/bin/xvfb-run -a -e /tmp/selenium.log -w 0 /usr/bin/python2.7
并得到像
这样的错误(<class 'selenium.common.exceptions.WebDriverException'>, WebDriverException(), <traceback object at 0x7fc7cfc9c128>)
奇怪的是我什至没有得到完整的堆栈跟踪,xvfb-run 的-e 选项也没有在文件中返回任何错误。
这是我的代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
f = webdriver.ChromeOptions()
browser =webdriver.Chrome(executable_path='/home/local/chromedriver',chrome_options=f)
browser.get(url)
browser.quit()
我也试过
executable_path='/usr/bin/chromedriver' 并且没有 executable_path
但得到同样的错误。
它最初是使用带有 firefox 的 python 2.6 。
我检查了大约 10-15 个类似的问题,甚至关于如何启用更多跟踪或调试,但似乎没有一个解决方案在这里对我有用。
硒版本 3.141.0
编辑: 我更新了一些代码以便能够获得完整的堆栈跟踪,但我得到了这个错误,
WebDriverException:消息:浏览器之前似乎已经退出 我们可以连接。
多一点挖掘,发现它与硒/浏览器有关 安装旧的 selenium 版本 2.53
因此上面的错误消失了,但现在我正在通过对等错误重置连接,下面是堆栈
(<class 'socket.error'>, error(104, 'Connection reset by peer'), <traceback object at 0x1e1e320>)
Traceback (most recent call last):
File "/var/www/Goose/src/goose/network.py", line 137, in get_html
browser.get(url)
File "/var/www/Goose/src/selenium/webdriver/remote/webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "/var/www/Goose/src/selenium/webdriver/remote/webdriver.py", line 231, in execute
response = self.command_executor.execute(driver_command, params)
File "/var/www/Goose/src/selenium/webdriver/remote/remote_connection.py", line 395, in execute
return self._request(command_info[0], url, body=data)
File "/var/www/Goose/src/selenium/webdriver/remote/remote_connection.py", line 426, in _request
resp = self._conn.getresponse()
File "/usr/lib64/python2.6/httplib.py", line 1049, in getresponse
response.begin()
File "/usr/lib64/python2.6/httplib.py", line 433, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python2.6/httplib.py", line 389, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "/usr/lib64/python2.6/socket.py", line 479, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 104] Connection reset by peer
即使requests [security] 已安装,因为我已经看到了一个原因。
【问题讨论】:
-
使用错误堆栈跟踪更新问题。我们需要知道
(<class 'selenium.common.exceptions.WebDriverException'>, WebDriverException(), <traceback object at 0x7fc7cfc9c128>)来自哪一行。 -
@DebanjanB ,编辑添加更多信息,
标签: python-2.7 selenium selenium-webdriver selenium-chromedriver