selenium.common.exceptions.WebDriverException:消息:'无法连接到GhostDriver'

sym*_*ech 17 python port phantomjs selenium-webdriver ghostdriver

我试图运行PhantomJS从内selenium.webdriverCentOS的服务器上.PhantomJS在路径中并且从终端正常运行.但是在脚本中它似乎已启动,但之后无法在指定端口上到达(我尝试了2个不同的打开端口,来自我的提供程序29842和60099,它们都不工作,并且没有指定端口也没有启动它).

错误发生在selenium.webdriver.common.utils:

try:
    socket_ = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socket_.settimeout(1)
    socket_.connect(("localhost", port))
    socket_.close()
    return True
except socket.error:
    return False
Run Code Online (Sandbox Code Playgroud)

这是从我的脚本(我尝试没有任何参数,以及编写可执行文件的完整路径,但都没有工作):

self.browser = webdriver.PhantomJS(
            port=29842,
            desired_capabilities={
                'javascriptEnabled': True,
                'platform': 'windows',
                'browserName': 'Mozilla',
                'version': '5.0',
                'phantomjs.page.settings.userAgent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36"
            }
        )
Run Code Online (Sandbox Code Playgroud)

这是初始化webdriver的脚本selenium.webdriver.phantomjs.service.我检查并subprocess.Popen实际上lauches phantomjs,错误发生在while循环:

    try:
        self.process = subprocess.Popen(self.service_args,
                                        stdout=self._log, stderr=self._log)

    except Exception as e:
        raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)

    count = 0
    while not utils.is_connectable(self.port):
        print utils.is_connectable(self.port)
        count += 1
        time.sleep(1)
        if count == 30:
             raise WebDriverException("Can not connect to GhostDriver")
Run Code Online (Sandbox Code Playgroud)

所有软件包都是最新版本:python 2.7,selenium 2和phantomjs 1.9二进制文件,集成了ghostdriver.我在Ubuntu本地计算机上使相同的脚本正常工作,与我在服务器上执行的操作完全相同.服务器上有什么不同?

use*_*431 9

升级到新版本后,我在Ubuntu上遇到了这个问题.我重新安装了所有的nodejs和python包,但我认为解决了这个问题的方法是确保nodejs可执行文件符号链接到node.

这些是我使用的命令:

apt-get remove node nodejs
apt-get install build-essential python-dev phantomjs npm nodejs
ln -s /usr/bin/nodejs /usr/bin/node
npm install -g phantomjs
pip install selenium bson BeautifulSoup pymongo
Run Code Online (Sandbox Code Playgroud)