When I send request to google api (using either axios or just https), e.g.

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

But if I send request to , it works just fine. I have googled the error, but I can't find much useful information. Here 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

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 

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: "", 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 = ' 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.

8

3 Answers

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

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

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

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy