selenium+phantomjs报错:Unable to find a free port的分析和解决
selenium+phantomjs报错:Unable to find a free port的分析和解决
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;
}
selenium+phantomjs报错:Unable to find a free port的分析和解决的更多相关文章
- selenium python 报错“ unable to find binary in default location”
selenium python 报错如下: raise exception_class(message, screen, stacktrace)selenium.common.exceptions.W ...
- python selenium phantomjs 报错
报错: webdriver.PhantomJS() raise exception_class(value)selenium.common.exceptions.WebDriverException: ...
- 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 ...
- selenium + PhantomJS使用时 PhantomJS报错解决
selenium + PhantomJS使用时 PhantomJS报错解决 在做动态网页爬虫时用到了selenium + PhantomJS,安装好之后运行时报错: UserWarning: Sele ...
- delphi调试需要管理员权限程序报错“Unable to create process:请求的操作需要提升”
delphi调试启动需要UAC权限的程序的时候会报错“Unable to create process:请求的操作需要提升”.这是因为delphi没有以管理员身份启动,这样delphi createp ...
- AS添加依赖报错Unable to merge dex
AS添加依赖报错Unable to merge dex 最近在给项目添加依赖的时候,要给项目导入Bmob的SDK,参照Bmob的官方文档,可以直接在app的build.gradle文件中添加 //Bm ...
- centos6.5环境wget报错Unable to establish SSL connection
centos6.5环境wget报错Unable to establish SSL connection [root@centossz008 src]# wget --no-check-certific ...
- linux 下通过xhost进入图形界面,经常会出现报错“unable to open display”
linux 下通过xhost进入图形界面,经常会出现报错“unable to open display” linux下的操作步骤如下: [root@localhost ~]# vncserver N ...
- 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 一些关键的sql语句练习 和选择题 有用 sql语句练习 挺好
一. 选择题 1.SQL语言是( C )语言. A.层次数据库 B.网络数据库 C.关系数据库 D.非数据库 redis 是 3.如果在where子句中有两个条件要同时满足,应该用哪个 ...
- R: data.frame 生成、操作数组。重命名、增、删、改
################################################### 问题:生成.操作数据框 18.4.27 怎么生成数据框 data.frame.,,及其相关操 ...
- 12、geo数据上传
1.注册一个NCBI账户 注册geo账户(老用户和新用户): https://www.ncbi.nlm.nih.gov/geo/submitter/ 有3个月的时间 GEO DataSets > ...
- Struts2学习第七课 result
result 是action节点的子节点 result 代表action方法执行后,可能去的一个目的地 一个action节点可以配置多个result子节点. result的name属性值对应着acti ...
- HTML5学习笔记(七)HTML5 服务器发送事件(Server-Sent Events)
Server-Sent 事件指的是网页自动获取来自服务器的更新. 以前也可能做到这一点,前提是网页不得不询问是否有可用的更新.通过服务器发送事件,更新能够自动到达. EventSource 对象用于接 ...
- nginx配置同一域名下,共存2个nodejs项目
项目背景: 1.官网需要改版,使用nodejs nuxt框架进行重构 2.官网改版没有全部完成.但需要上线首页 项目需求: 1.让首页内容显示为新项目 2.让老官网的内容可以被访问到(比如www.n. ...
- [Emacs] Emacs使用介绍
详细,可参考该文档(转载):Emacs 快速指南 - 原生中文手册 C-x C-c 关闭Emacs会话 C-v/M-v 向前/后翻页 C-n/C-p 光标向下/上移一行 C-f/C-b 光标向前/后移 ...
- 图的最小切隔问题Minimum Cuts
前提条件是这样的:输入一个图(可以是有向图,也可以是无向图,允许平行边存在),我们要做的事情是将这个图切割成两个子图,(切割的定义:将图中的所有顶点分为两个集合A和B,要求这两个集合非空)假设这个图中 ...
- 图解 SSH上传安装tomcat
安装步骤: 1.SSH上传压缩包 2.[root@localhost soft]# tar -zxvf apache-tomcat-7.0.61.tar.gz //解压安装 解压结果 3.[r ...
- poj 2068 Nim
Nim POJ - 2068 题目大意:多组数据,两人轮流操作,n轮一循环,给出总石子数和这n轮每次两人能取的石子上限(下限为1).取到最后一颗者输. /* f[i][j]表示在第i轮中一共有j个石子 ...