selenium+phantomjs报错:Unable to find a free port的分析和解决

Table of Contents

1 现象

在做项目时,发现在某台机器上使用selenium+phantomjs时报如下错误:

java.lang.RuntimeException: Unable to find a free port
at org.openqa.selenium.net.PortProber.findFreePort(PortProber.java:67)
at org.openqa.selenium.phantomjs.PhantomJSDriverService$Builder.build(PhantomJSDriverService.java:443)
...

2 分析

通过跟踪源代码(org.openqa.selenium.net.PortProber.createAcceptablePort),发现:

if (FIRST_PORT == LAST_PORT) {
return FIRST_PORT;
}

在该服务器上,FIRSTPORT = LASTPORT = 1024,因此总是返回1024。

查看服务器的可用本地端口配置,如下:

[gyx@interface01 ~]$ cat /proc/sys/net/ipv4/ip_local_port_range
1024 65535

因为这台机器的最低可用端口配置成了1024,而其他机器都比这个大很多,因此造成了上述问题。

3 解决办法

因为该服务器还有别的用处,不能随意修改可用端口配置,所以,暂时通过修改createAcceptablePort中相应代码解决问题。如下:

if (FIRST_PORT == LAST_PORT) {
// return FIRST_PORT;
final int randomInt = random.nextInt();
System.out.println("randomInt = " + randomInt);
final int portWithoutOffset = Math.abs(randomInt % (HIGHEST_PORT - START_OF_USER_PORTS + 1));
return portWithoutOffset + FIRST_PORT;
}

Author: galaxy

Created: 2016-07-28 Thu 09:58

Emacs 24.5.6 (Org mode 8.2.10)

Validate

selenium+phantomjs报错:Unable to find a free port的分析和解决的更多相关文章

  1. selenium python 报错“ unable to find binary in default location”

    selenium python 报错如下: raise exception_class(message, screen, stacktrace)selenium.common.exceptions.W ...

  2. python selenium phantomjs 报错

    报错: webdriver.PhantomJS() raise exception_class(value)selenium.common.exceptions.WebDriverException: ...

  3. selenium启动报错“ incorrect JSON status mapping for 'unknown error' (500 expected)”

    前面讲了工程启动报错“selenium启动报错Unable to read VR Path Registry from C:\Users\clinva\AppData\Local\openvr\ope ...

  4. selenium + PhantomJS使用时 PhantomJS报错解决

    selenium + PhantomJS使用时 PhantomJS报错解决 在做动态网页爬虫时用到了selenium + PhantomJS,安装好之后运行时报错: UserWarning: Sele ...

  5. delphi调试需要管理员权限程序报错“Unable to create process:请求的操作需要提升”

    delphi调试启动需要UAC权限的程序的时候会报错“Unable to create process:请求的操作需要提升”.这是因为delphi没有以管理员身份启动,这样delphi createp ...

  6. AS添加依赖报错Unable to merge dex

    AS添加依赖报错Unable to merge dex 最近在给项目添加依赖的时候,要给项目导入Bmob的SDK,参照Bmob的官方文档,可以直接在app的build.gradle文件中添加 //Bm ...

  7. centos6.5环境wget报错Unable to establish SSL connection

    centos6.5环境wget报错Unable to establish SSL connection [root@centossz008 src]# wget --no-check-certific ...

  8. linux 下通过xhost进入图形界面,经常会出现报错“unable to open display”

    linux 下通过xhost进入图形界面,经常会出现报错“unable to  open display” linux下的操作步骤如下: [root@localhost ~]# vncserver N ...

  9. git clone 报错Unable to negotiate with xxx.xxx.xxx.xxx port 12345: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

    在执行git clone命令报错 Unable to negotiate with xxx.xxx.xxx.xxx port 12345: no matching key exchange metho ...

随机推荐

  1. python的gzip库使用方法

    解压gzip文件示例: import gzip f = gzip.open('file.txt.gz', 'rb') file_content = f.read() f.close() 创建gzip文 ...

  2. 华为USG6320做双线-基于源地址的策略路由

    通过配置策略路由实现不同源地址数据通过不同的链路转发. 组网需求 某企业公司拉了两条电信的光纤,分别为静态光纤和拨号光纤,前者主要用于服务器,后者则用于一般办公. 需求如下: 静态光纤:服务器专用 拨 ...

  3. mysql- 修改root密码的多种方法

    MySQL修改root密码的多种方法  方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' ...

  4. new/delete 和malloc/free 的区别

    new/delete 和malloc/free 的区别 一.基本概念malloc/free:1.函数原型及说明:      void *malloc(long NumBytes):该函数分配了NumB ...

  5. service的生命周期以及两种service的差异

    可以看到,两种service的生命周期都相对简单,有一点不同的是,Intentservice每次调用的时候都执行onstartcommand,而boundservice一旦启动了之后,就不会每次执行o ...

  6. 【总结整理】JQuery基础学习---事件篇

    jQuery鼠标事件之click与dbclick事件 用交互操作中,最简单直接的操作就是点击操作.jQuery提供了两个方法一个是click方法用于监听用户单击操作,另一个方法是dbclick方法用于 ...

  7. swiper实现左右滑动图片

    ref:http://www.swiper.com.cn/usage/index.html help:https://segmentfault.com/a/1190000002962202 src: ...

  8. Deep Image Matting

    论文地址:https://arxiv.org/abs/1703.03872 TF复现地址:https://github.com/Joker316701882/Deep-Image-Matting 领域 ...

  9. rxjs入门6之合并数据流

    一 concat,merge,zip,combineLatest等合并类操作符 以上操作符在版本6中已经只存在静态方法,不能在pipe中使用. import {concat,merge,zip,com ...

  10. [WIP]laravel 构成的概念

    创建: 2019/06/21 生命周期  概论    检索service provider               service container                     se ...