node-sdk: createSession from Assistant V2 is not working behind http proxy

Overview My enterprise is using a http proxy and because of that createSession from ibm-watson/assistant/v2 is not working. Internally a token from https://iam.cloud.ibm.com/identity/token is created with an axios https post call. I think axios is not working with https post calls and http proxy.

Expected behavior

{
  "session_id": "XXX-XXXX-XXXX-XXX-XXXX."
}

Actual behavior

Error: Response not received. Body of error is HTTP ClientRequest object
    at RequestWrapper.formatError (XXX\watson\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:232:21)
    at XXX\watson\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:220:29
    at processTicksAndRejections (internal/process/task_queues.js:82:5) {

How to reproduce Use a http proxy and execute this code:

const AssistantV2 = require('ibm-watson/assistant/v2'); // watson sdk

const assistant = new AssistantV2({
    version: '2019-06-14',
    iam_apikey: XYZ',
    url: 'https://XXX.watsonplatform.net/assistant/api',
    headers: {
        'X-Watson-Learning-Opt-Out': 'true'
    }
});

assistant.createSession({
    assistant_id: 'XXX-XXX-XXX-XXX'
})
    .then(res => {
        console.log(JSON.stringify(res, null, 2));
    })
    .catch(err => {
        console.log(err);
    });

SDK Version 4.2.1

Additional information:

  • OS: Windows 10
  • nodejs: 12.5.0

Additional context I found this homepage: https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d and added this code in requestwrapper.js:

 var tunnel = require("tunnel");

     var agent = tunnel.httpsOverHttp({
         proxy: {
             host: 'XXX.example.com',
             port: YYYY,
         },
     });

     axiosConfig.httpsAgent = agent;
     axiosConfig.proxy = false;

     this.axiosInstance = axios_1.default.create(axiosConfig);

After this everything is working.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

@dpopp07 i will try your potential fix as soon as possible. πŸ˜ƒ

From my side everything is fine with v4.3.2. πŸ˜ƒ

I followed the readme.md and everything is working for this DiscoveryV1 version. I used the current released version from DiscoveryV1 for the current released from ibm-watson and it’s not working. So everything looks good with this branch. πŸ˜ƒ

@dpopp07

I used this documentation to generate a token: https://cloud.ibm.com/docs/services/watson?topic=watson-iam. After getting a token I used iam_access_token to configure, removed iam_apikey property, my AssistantV2. But it’s still not working without my workaround.