【问题标题】:"Client network socket disconnected before secure TLS connection was established", node 10“客户端网络套接字在建立安全 TLS 连接之前断开”,节点 10
【发布时间】:2019-05-04 17:07:16
【问题描述】:

当我向 google api(使用 axios 或仅使用 https)发送请求时,例如https://www.googleapis.com/blogger/v3/blogs/2399953?key=...

我总是遇到“在建立安全 TLS 连接之前断开客户端网络套接字”错误。

但如果我向https://api.github.com 发送请求,它就可以正常工作。我已经用谷歌搜索了这个错误,但我找不到太多有用的信息。这里https://github.com/nodejs/node/issues/21088 说如果服务器使用 TLS 1.0,它可能会发生,但显然不是我的情况。

我也尝试googleapis,但仍然遇到同样的错误。

知道如何修复错误吗?

----更新----

我的问题已于 5 个月前结束。我针对 googleapi 打开了an issue,它也被关闭了。我已经放弃了,但令我惊讶的是,它一直在增加流量。所以我更新了我的问题,希望它会重新打开。

首先,google api已经移到这里https://github.com/googleapis/google-api-nodejs-client

其次,只需使用 vpn 在那里运行the first example(使用 vpn,因为无论出于何种原因,谷歌服务被阻止),我将得到 connect ETIMEDOUT,同时我可以从浏览器获取结果。

const {google} = require('googleapis');
const blogger = google.blogger({
  version: 'v3',
  auth: 'YOUR API KEY'
});

blogger.blogs.get({blogId: '3213900'}, (err, res) => {
  if (err) {
    console.error(err);
    throw err;
  }
  console.log(`The blog url is ${res.data.url}`);
});
//But I can get result in browser https://blogger.googleapis.com/v3/blogs/3213900?key=xxx

我认为这个问题是可以解决的,因为 nodejs 没有通过我的 vpn 代理发送请求。所以我的问题和这个有点相关,What could cause "connect ETIMEDOUT" error when the URL is working in browser?

但是那里的解决方案对我不起作用。这个 SO How can I use an http proxy with node.js http.Client? 中的一个答案提到使用 request 并且它有效!

var request = require("request");

request(
  {
    url:
      "https://blogger.googleapis.com/v3/blogs/3213900?key=xxx",
    method: "GET",
    proxy: my-vpn-proxy,
  },
  function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log(body);
    }
  }
);

太糟糕的请求已被弃用!我也不能让 axios 工作!

我也试过tunnel,得到read ECONNRESET error;我尝试了global-tunnel-ng 并得到了错误

TypeError: Cannot read property 'proxy' of undefined
    

但是https-proxy-agent 也可以,

var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');
 
// HTTP/HTTPS proxy to connect to
var proxy = 'my-vpn-proxy';

var endpoint = 'https://blogger.googleapis.com/v3/blogs/3213900?key=xxx';
var opts = url.parse(endpoint);
 
var agent = new HttpsProxyAgent(proxy);
opts.agent = agent;
 
https.get(opts, function (res) {
  console.log('"response" event!', res.headers);
  res.pipe(process.stdout);
});

所以我认为这个问题可能是可以解决的。

【问题讨论】:

  • 代理或防火墙阻止请求?在浏览器中打开https://www.googleapis.com 时是否出现类似错误?
  • 哦,对了。我正在使用 vpn,但如果在 chrome 中打开该链接,我可以获得正确的结果
  • 代码?日志?可以帮助任何人解决问题的信息?
  • https://www.googleapis.com 是的,我也有在浏览器上打开它
  • https://www.googleapis.com 它没有找到我遇到了 firebase 存储问题:message: 'request to https://storage.googleapis.com/upload/storage/v1/b/res/o?uploadType=multipart&name=61928166801.png failed, reason: Client network socket disconnected before secure TLS connection was established', > type: 'system', > errno: 'ECONNRESET', > code: 'ECONNRESET' > }

标签: node.js ssl vpn


【解决方案1】:

如果其他人面临同样的问题,可能的解决方案(如果您使用的是 Windows 操作系统)是按照以下过程进行操作:

  • 按 Windows 键
  • 搜索 Internet 选项
  • 点击“Internet 选项”
  • 点击“连接”
  • 进入局域网设置
  • 取消选中“为 LAN 使用代理服务器 ....”

它应该可以工作,但永久的解决方案是确保您打开所有可能会自动为您设置代理的软件。

【讨论】:

    【解决方案2】:

    问题被重新打开后,我针对google api提出了another issue,终于得到了答案!

    所以google api已经支持使用代理了,check here

    【讨论】:

      【解决方案3】:

      此错误可能与您的代理有关。如果在 Unix 上,请检查您的 HTTP_PROXY 和 HTTPS_PROXY 环境变量。

      【讨论】:

      • 我使用的是 Windows 操作系统。相同的解决方案有效。通过修复这两个变量,我的问题就消失了。谢谢。
      猜你喜欢
      • 2020-08-15
      • 2020-09-18
      • 2020-08-06
      • 2020-04-22
      • 2020-08-07
      • 2021-09-15
      • 2022-11-10
      • 2021-02-25
      • 1970-01-01
      相关资源
      最近更新 更多