节点4.2.0 phantom stdout:NETWORK_ERR:XMLHttpRequest异常101:同步请求中
Node 4.2.0 phantom stdout: NETWORK_ERR: XMLHttpRequest Exception 101: A network error occurred in synchronous requests
在节点4.2.0中调用以下代码,它在节点cron作业中执行,而不是通过终端执行。我"请求"的网站是http://www.milb.com/index.jsp?sid=t402.
module.exports.dynamicRequest = function(url, callback) {
var makeDynamicRequest = function(attempt) {
if (attempt === 4) {
svghost.delPhantom();
return callback(new Error('Phantom had 3 failures'));
}
svghost.getPhantom(function(err, ph) {
if (err) {
console.log(err.stack);
setTimeout(function() {
ph.exit();
svghost.delPhantom();
attempt++;
makeDynamicRequest(attempt);
}, Math.pow(2, attempt) * 300);
} else {
ph.createPage(function(page) {
page.open(url, function(status) {
if (status === 'success') {
page.get('content', function(content) {
ph.exit();
svghost.delPhantom();
callback(null, content);
});
} else {
ph.exit();
svghost.delPhantom();
setTimeout(function() {
attempt++;
makeDynamicRequest(attempt);
}, Math.pow(2, attempt) * 300);
}
});
});
}
});
};
makeDynamicRequest(1);
};
svghost只是一个简单的phantom包装器,它递归地尝试创建一个phantom对象,直到成功为止。我相信svghost不是问题所在。这100%在本地工作,但当cron作业在我们的服务器上运行时,我看到了这个错误:phantom stdout: NETWORK_ERR: XMLHttpRequest Exception 101: A network error occurred in synchronous requests.
这是堆栈跟踪:
phantom stdout: /srv/apps/scraper/node_modules/spoton/node_modules/phantom/shim.js:7608 in send
/srv/apps/scraper/node_modules/spoton/node_modules/phantom/shim.js:7608 in _start
/srv/apps/scraper/node_modules/spoton/node_modules/phantom/shim.js:7635
使用phantom.create
创建幻影实例时,应添加--web-security=no
参数或使用options
对象并向其添加'web-security':'no'
。
它会产生这样的结果:
phantom.create({'web-security':'no'}, callback...)
并且你的NETWORK_ERROR不应该消失
有关更多信息,请参阅此堆栈或tihs github问题。
相关文章:
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- 为什么浏览器没有为语法错误抛出异常
- java,javascript签名的小程序(文件选择,ftp上传)安全性/套接字异常
- node.js和express中的异常处理
- 派生进程的stdout在管道传输时工作异常
- NodeJS和pg promise,捕获PostgreSQL异常
- 当显式定义控制器参数时,默认模型绑定器会发生异常
- 显示引导弹出操作异常的逻辑
- 调用谷歌地图路线服务时未捕获的异常
- web配置http到https重定向异常
- 转换异常时间&Datestring到JavaScript日期
- 为什么在python中使用异常比javascript更容易接受
- PHP REST服务抛出异常——希望避免控制台错误
- JS异常:animate不是一个函数
- 在蓝鸟中处理异常
- Meteor:异步函数回调异常:onAfterAction
- 在js中捕获自定义异常
- 测试抛出异常的函数
- 奇怪的html呈现异常