102

When I send request to google api (using either axios or just https), e.g. https://www.googleapis.com/blogger/v3/blogs/2399953?key=...

I always hit the "Client network socket disconnected before secure TLS connection was established" error.

But if I send request to https://api.github.com, it works just fine. I have googled the error, but I can't find much useful information. Here https://github.com/nodejs/node/issues/21088 said if the server uses TLS 1.0, it may happen but apparently it is not my case.

I also try googleapis but still hit the same error.

Any idea how to fix the error ?

---- update ----

My question was closed 5 months ago. I opened an issue against googleapi and it was also closed. I had gave it up but to my surprise it keeps getting traffic. So I updated my question and hope it will be reopened.

First, google api has moved to here https://github.com/googleapis/google-api-nodejs-client

Second, just using vpn to run the first example there (using vpn because google service is blocked for whatever reason), I will get connect ETIMEDOUT while I can get the result from browser.

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

I think the problem was solvable because nodejs doesn't send the request through my vpn proxy. So my question is somewhat related to this one, What could cause "connect ETIMEDOUT" error when the URL is working in browser?

But the solution there did not work for me. One answer in this SO How can I use an http proxy with node.js http.Client? mentioned using request and it works!

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);
    }
  }
);

Too bad request was deprecated! I can't make axios works too!

I also tried tunnel and got read ECONNRESET error; I tried global-tunnel-ng and got the error

TypeError: Cannot read property 'proxy' of undefined
    

But https-proxy-agent works too,

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);
});

So I think this problem may be solvable.

10
  • 1
    Proxy or firewall blocking the request? Do you get a similar error when opening https://www.googleapis.com in a browser?
    – robertklep
    Commented Dec 3, 2018 at 14:31
  • 1
    Oh right. I am using vpn but I can get the correct result if open that link in chrome
    – Qiulang
    Commented Dec 3, 2018 at 14:32
  • Code? Log? Information that would help anybody solve the problem?
    – user207421
    Commented Mar 20, 2020 at 9:02
  • https://www.googleapis.com Yes I also having opening this on browser Commented Mar 30, 2020 at 9:33
  • 1
    https://www.googleapis.com it gives not found I stuck on a problem with firebase storage: 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' > } Commented Apr 5, 2020 at 7:33

7 Answers 7

6

In case, someone else faces this same problem, a possible solution (if you are using windows OS), is to follow the process below:

  • Press the Windows Key
  • Search For Internet Options
  • Click on "Internet Options"
  • Click On "Connection"
  • Go to LAN Settings
  • Uncheck "Use Proxy Server for LAN ...."

It should work but the permanent solution is to make sure you turn all software that might be automatically setting up proxy for you.

0
6

After the question was re-opened I raised another issue against google api and finally got the answer!

So google api has supported using proxy, check here

3

This error could be related to your proxy. If on Unix, check your HTTP_PROXY and HTTPS_PROXY environment variables.

3
  • I am using Windows OS. The same solution works. By fixing these two variables, my issue is gone. Thanks.
    – David Ruan
    Commented Nov 5, 2021 at 15:11
  • 10
    Maybe you should mention how to check these variables.
    – KevinH
    Commented Jan 20, 2022 at 7:18
  • @KevinH, in python, import os; os.environ["https_proxy"]. This will raise an error if you have not set it yet. If had, in the CMD enter set https_proxy= to remove the value.
    – Shayan
    Commented Apr 18, 2023 at 14:18
3

If you run npm/yarn install from a terminal, temporarily cancel the proxy configuration:

unset https_proxy && unset http_proxy.

1

In my case it was caused by wrong Node version. Had to run nvm use because it was a different project using version 16, while I was using 14 in previous project.

0

Another useful fix is maybe you forgot to add your IP address try adding your IP address from the network access tab

-1

I got this error when running npm install:

npm ERR! code ECONNRESET
npm ERR! network Client network socket disconnected before secure TLS connection was established
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

The reason is there is an npm link to a locally developed module. The module's version does not match what's required in package.json.

After I remove the link, npm install started to work.

Not the answer you're looking for? Browse other questions tagged or ask your own question.