watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 669 forks source link

EPROTO 140502679459712:error:1408F10B:SSL routines:ssl3_get_record:wrong version number- Response not received - no connection was made to the service. #996

Closed dvf3101 closed 4 years ago

dvf3101 commented 5 years ago

Hi,

we have done the migration of Watson service and the consequent update of the library ibm-watson.

After the update our script doesn't work properly and returns the following error:

{ Error: write EPROTO 140502679459712:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:

at RequestWrapper.formatError (/home/Mauden01/workspace/script_upload/upload_doc_js/node_modules/ibm-cloud-sdk-core/lib/request-wrapper.js:208:21)
at /home/Mauden01/workspace/script_upload/upload_doc_js/node_modules/ibm-cloud-sdk-core/lib/request-wrapper.js:196:25
at process._tickCallback (internal/process/next_tick.js:68:7)

message: 'write EPROTO 140502679459712:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:\n', statusText: 'EPROTO', body: 'Response not received - no connection was made to the service.' }

To understand if the problem was inherent with the environment, we have tried the following simple code, but returns the same error:

var DiscoveryV1 = require('ibm-watson/discovery/v1');
const { IamAuthenticator } = require('ibm-watson/auth');

const discovery = new DiscoveryV1({
    version: '2019-04-30',
    authenticator: new IamAuthenticator({
        apikey: '*************',
    }),
    url: '*************'
});

discovery.getCollection({
    environmentId: "********",
    collectionId: "********",
}).then(collection => {
    console.log('collection', collection)
}).catch(err => {
    console.log('---------------- ERROR GETCOLLECTION:', err)
})

We have tried the same code in local and works properly.

Another test done consists in the use of request library on the VM. Following the code:

const request = require('request');

var env = "********";
var col = "********";
var document_id = "1234"

request.get(`https://gateway-fra.watsonplatform.net/discovery/api/v1/environments/${env}/collections/${col}/documents/${document_id}`, {
    qs: {
        version: '2019-04-30'
    },
    auth: {
        user: 'apikey',
        pass: '************',
        sendImmediately: false
    },
    json: true
}, function (err, data) {
    if(err){
        console.log('err', err)
    }else{
        console.log('data',data)
    }
});

We have done the same test with Axios library and it works properly on the VM:

const axios = require("axios")

var environment_id = "**********";
var collection_id = "***********";
const {
    IamAuthenticator
} = require('ibm-watson/auth');

async function run() {
    try {
        let response = await axios({
            url: `https://gateway-fra.watsonplatform.net/discovery/api/v1/enviro                                                                                                                                                                                                nments/${environment_id}/collections/${collection_id}?version=2019-04-30`,
            auth: {
                username: 'apikey',
                password: '************'
            },
        })
        console.log(response.data);
    } catch (e) {
        console.log(e.message)
    }
}

run()

Request and Axios library work properly on the VM. So from this tests, we think that the problem is between the setting on the VM and the ibm-watson library.

Following some info of the VM where we run the code:

cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"

node -v v10.2.0

npm --versions { upload_doc_js: '1.0.0', npm: '5.6.0', ares: '1.14.0', cldr: '33.0', http_parser: '2.8.0', icu: '61.1', modules: '64', napi: '3', nghttp2: '1.29.0', node: '10.2.0', openssl: '1.1.0h', tz: '2018c', unicode: '10.0', uv: '1.20.3', v8: '6.6.346.32-node.8', zlib: '1.2.11' }

openssl version OpenSSL 1.0.2k-fips 26 Jan 2017

echo "$http_proxy" http://proxy.online.***.net:8080/

echo "$https_proxy" http://proxy.online.***.net:8080/

Thanks

dpopp07 commented 5 years ago

Hm, that's interesting that it is working with axios directly. It looks like the error is coming from the proxy. Will you try using this method of configuring the proxy and let me know what your results are? You will need to add this configuration both to the constructor and the authenticator.

dvf3101 commented 5 years ago

Hi,

we have used the method of configuring the proxy, but the error is the same. Following the code:

const tunnel = require("tunnel");
let DiscoveryV1 = require('ibm-watson/discovery/v1');
const {
    IamAuthenticator
} = require('ibm-watson/auth');
console.log('start')

const discovery = new DiscoveryV1({
    version: '2019-04-30',
    authenticator: new IamAuthenticator({
        apikey: '******'
    }),
    proxy: false,
    httpsAgent: tunnel.httpsOverHttp({
      proxy: {
        host: "proxy.online.*****.net",
        port: 8080
      }
    }),
    url: 'https://gateway-fra.watsonplatform.net/discovery/api'
});

var env = "*****";
var col = "*****";

async function run() {
    try {
        let collection = await discovery.getCollection({
            environmentId: env,
            collectionId: col
        })
        console.log(collection)
    } catch (e) {
        console.log(e)
    }

}

run()

Following the error:

{ Error: write EPROTO 140169508251520:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:

at RequestWrapper.formatError (/home/Mauden01/workspace/script_upload/upload_doc_js/testDiscovery/node_modules/ibm-cloud-sdk-core/lib/request-wrapper.js:208:21)
at /home/Mauden01/workspace/script_upload/upload_doc_js/testDiscovery/node_modules/ibm-cloud-sdk-core/lib/request-wrapper.js:196:25
at process._tickCallback (internal/process/next_tick.js:68:7)

message: 'write EPROTO 140169508251520:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:\n', statusText: 'EPROTO', body: 'Response not received - no connection was made to the service.' }

From some analysis, we have seen that in the classes typescript of different services (for example Discovery and Assistant), we have not found any params called httpsAgent and proxy. The library version is "ibm-watson": "^5.1.0". Could it be this the problem?

Thanks

dpopp07 commented 5 years ago

That is not problem, httpsAgent is an axios parameter that gets passed straight to axios. The issue may be that the httpsAgent also needs to be passed to the IamAuthenticator, since the authenticator is also making a request (for a token).

const httpsAgent = tunnel.httpsOverHttp({
  proxy: {
    host: "proxy.online.*****.net",
    port: 8080
  }
});
const discovery = new DiscoveryV1({
    version: '2019-04-30',
    authenticator: new IamAuthenticator({
        apikey: '******',
        httpsAgent,
    }),
    proxy: false,
    httpsAgent,
    url: 'https://gateway-fra.watsonplatform.net/discovery/api'
});
dvf3101 commented 5 years ago

Hi,

we passed the httpsAgent to the IamAuthenticator, how you have written in your code and now we receive the following error:

{ Error: write EPROTO 139755673397120:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:

at RequestWrapper.formatError (/home/Mauden01/workspace/script_upload/upload_doc_js/testDiscovery/node_modules/ibm-cloud-sdk-core/lib/request-wrapper.js:208:21)
at /home/Mauden01/workspace/script_upload/upload_doc_js/testDiscovery/node_modules/ibm-cloud-sdk-core/lib/request-wrapper.js:196:25
at process._tickCallback (internal/process/next_tick.js:68:7)

message: 'write EPROTO 139755673397120:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:\n', statusText: 'EPROTO', body: 'Response not received - no connection was made to the service.' }

How can we solve it?

Thanks

FrancescoDiMaggio commented 5 years ago

Hello everyone, do you have any update about this Issue?

mkistler commented 4 years ago

Regarding the error message you are getting, I found this post that says:

This error usually occurs if you attempt to connect to something that isn't using SSL/TLS. A wireshark trace might help you identify what is going on.

Given that you are using a proxy, I guess there are three possible sources of the error:

As I look over the notes above, this jumps out:

echo "$http_proxy" http://proxy.online.***.net:8080/

echo "$https_proxy" http://proxy.online.***.net:8080/

This looks to me like the http and https proxy are both set to the same endpoint, and I really don't think that's possible -- that one endpoint serves both. So I think the proxy configuration is somehow not right.

dvf3101 commented 4 years ago

Hi,

thanks for your comment. Unfortunately we are not the VM's owner, so we will report your comment to the owner.

We will reply here as soon as we have an answer.

Thanks

dvf3101 commented 4 years ago

Hi,

our customer is doing some check on VM. Instead is it possible that the error is generated by token service or Discovery? Could we verify this?

Thanks

dpopp07 commented 4 years ago

The error is likely not generated by the token service or Discovery, because a connection is never being established with the server. The request is dropping for some reason, likely due to what Mike mentioned in his comment.

dvf3101 commented 4 years ago

Hi,

thanks for your response. We are planning some changes to the proxy configuration in the next days. We will update you.

Thanks

dvf3101 commented 4 years ago

Hi,

your response has resolved the error and now the service works properly. Our customer has modified the proxy configuration.

Thanks

SoubhagyaPrustyTR commented 3 years ago

@dvf3101 - Maybe this is an old post, but we are seeing this issue in our server. Just wondering on the proxy configuration. The changes that you did, is it on the server hosting the code or is it the proxy server?

sujit2710 commented 3 years ago

while installing angular cli

sudo npm install -g @angular/cli

getting this error in ubuntu16.04

npm ERR! code EPROTO npm ERR! errno EPROTO npm ERR! request to https://registry.npmjs.org/@angular%2fcli failed, reason: write EPROTO 139787522484032:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: npm ERR!

npm ERR! A complete log of this run can be found in: npm ERR! /home/madan/.npm/_logs/2021-10-27T12_08_12_340Z-debug.log

xiaoxpai commented 2 years ago

o(╥﹏╥)o,I also encountered this problem,Has this error been resolved, please help me

PS E:\_IdeaProject\fork\renren-ui-master> npm install
npm ERR! code EPROTO
npm ERR! errno EPROTO
npm ERR! request to https://registry.npmmirror.com/semver failed, reason: write EPROTO 2924:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ALF\AppData\Roaming\npm-cache\_logs\2022-08-17T11_26_57_896Z-debug.log