Selenium WebDriver:socket.error:Peer连接重置

时间:2013-12-07 01:43:07

标签: python sockets python-2.7 selenium

我正在尝试使用PhantomJS运行Selenium WebDriver。

每当我尝试执行时:

from selenium import webdriver
x = webdriver.PhantomJS()
x.get('any address')

我收到以下错误消息:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
     File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 176, in get
    self.execute(Command.GET, {'url': url})
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 162, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 350, in execute
    return self._request(url, method=command_info[0], data=data)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 382, in _request
    resp = self._conn.getresponse()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1045, in getresponse
    response.begin()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
socket.error: [Errno 54] Connection reset by peer

有没有人知道可能会发生什么?我无法理解socket.py中发生了什么,似乎无法追踪__socket.pyd。此错误发生在本地计算机(OS X)上。

1 个答案:

答案 0 :(得分:0)

pip uninstall selenium
pip install selenium==2.3.7

显然,最新的Selenium版本与phantomjs 1.9.2不兼容。