我正在尝试PhantomJS从selenium.webdriverCentos 服务器内部运行。PhantomJS 在路径中并且从终端正常运行。但是在脚本中它似乎已启动,但之后无法在指定端口上访问(我尝试了来自我的提供商 29842 和 60099 的 2 个不同的打开端口,它们都不起作用,并且在没有指定端口的情况下也不会启动它)。
错误发生在这里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
这是来自我的脚本(我尝试不使用任何参数以及编写可执行文件的完整路径但均未成功):
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"
            }
        )
这是初始化 webdriver 的脚本selenium.webdriver.phantomjs.service。我检查并subprocess.Popen实际启动了 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")
所有软件包都是最新版本:python 2.7、selenium 2 和 phantomjs 1.9 二进制文件,并集成了 ghostdriver。我让相同的脚本在我的 Ubuntu 本地机器上正常工作,做的事情与我在服务器上做的完全一样。服务器上有什么不同?