I have been using the IBM Watson API and its node.js SDK. The problem I am facing is that the call to the Watson API using the node.js SDK always returns me the following error.
{ Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (_tls_wrap.js:1049:34)
at TLSSocket.emit (events.js:182:13)
at TLSSocket._finishInit (_tls_wrap.js:631:8) code:
'SELF_SIGNED_CERT_IN_CHAIN' }
I have tried setting the and 和 but with no luck.
var watson = require('watson-developer-cloud');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var assistant = new watson.AssistantV1({
iam_apikey: 'API-KEY',
version: '2018-09-20',
url: 'URL'
});
assistant.message({
workspace_id: 'WORKSPACE-ID',
input: {'text': 'Input-Text'},
}, function(err, response) {
if (err)
console.log('error:', err);
else
console.log(JSON.stringify(response, null, 2));
});
The url and iam_apikey in the code are incorrect:
var assistant = new watson.AssistantV1({
iam_apikey: 'API-KEY',
version: '2018-09-20',
url: 'URL'
});
In my code sample here https://github.com/IBM/watson-assistant-app-connect the initialization is:
const AssistantV1 = require('watson-developer-cloud/assistant/v1');
const assistant = new AssistantV1({
url: 'https://gateway.watsonplatform.net/assistant/api',
version: '2018-02-16'
});
It will pick up the api key from the environment variable ASSISTANT_IAM_APIKEY.
Temporarily I found the following workaround.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var assistant = new watson.AssistantV1({
iam_apikey: YOUR-API-KEY,
version: '2018-09-20',
url: YOUR-URL,
disable_ssl_verification: true
});
Here, setting disable_ssl_verification to true did the trick though I don't trust this to be a permanent way to move ahead with.
Please do not use process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
. It's a setting that will affect not only the IBM Watson Node.js SDK but also all your application.
We added a specific variable in the constructor to deal with servers using a self-signed certificate. disable_ssl_verification
only affect the HTTP library we use request
.
var assistant = new watson.AssistantV1({
iam_apikey: 'YOUR-API-KEY',
version: '2018-09-20',
url: 'YOUR-URL',
disable_ssl_verification: true
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.