我正在尝试追踪我的代码失败的原因,并显示以下错误:
{ Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443 }该错误的堆栈跟踪如下所示:
Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)我正在建立网络连接,但我没有尝试连接到localhost。
我使用的网络代码在其他上下文中运行良好(并连接到正确的主机)。
我使用的是brew安装程序提供的节点11.6.0,在brew "Cellar“目录结构中,字符串"net.js”似乎只出现在节点二进制文件本身中。换句话说,即使在
brew install --build-from-source node正在运行
find /usr/local/Cellar/node/11.6.0 -type f | xargs fgrep -l net.js只找到一个文件: /usr/local/Cellar/node/11.6.0/bin/node,并且该目录树中没有net.*文件。
如果这很重要,我的代码似乎触发了这个错误,如下所示:
const get_json_with_auth= async (channel, url) => {
const parsed_url= URL.parse(url);
return new Promise((good, fail) => {
let request= require('https').get({
hostname: parsed_url.hostname,
path: parsed_url.path,
headers: {
Authorization: get_auth('GET', channel, url)
}
});
console.log('url', url);
request.on('response', response=> {
const chunks= [];
response.on('data', data=> chunks.push(data));
response.on('end', ()=> good(JSON.parse(Buffer.concat(chunks).toString())));
});
request.on('error', err=> fail(err));
});
};(我在OSX高中赛拉。)
但是,再一次,我使用的url中的主机名没有解析为localhost (并且在其他上下文中工作得很好)。
我如何隔离这样的问题?
发布于 2019-01-19 03:57:36
使用环境变量NODE_DEBUG='net,tls,http,https‘运行我的代码,给了我足够的信息来识别(并隔离)这个问题。
https://stackoverflow.com/questions/54241944
复制相似问题