Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

API does not work - this.client.methodCall response never retrieved #5

Open
cyril23 opened this issue Oct 26, 2017 · 2 comments
Open

Comments

@cyril23
Copy link

cyril23 commented Oct 26, 2017

I tried your codesample, but the API is ready message never comes:

inwx({api: "production", user: "myusername", password: "mypassword"}, function(api){
  console.log("API is ready");

Trying with testing api produces the error (but OK, I don't even have an testing API account and don't known how to make one, so..):

4|inwx     | Error
4|inwx     |     at ClientRequest.<anonymous> 
 (/home/myusername/nodejs_apps/node_modules/inwx/lib/inwx.js:62:15)
4|inwx     |     at emitOne (events.js:77:13)
4|inwx     |     at ClientRequest.emit (events.js:169:7)
4|inwx     |     at Socket.socketErrorListener (_http_client.js:258:9)
4|inwx     |     at emitOne (events.js:77:13)
4|inwx     |     at Socket.emit (events.js:169:7)
4|inwx     |     at emitErrorNT (net.js:1256:8)
4|inwx     |     at nextTickCallbackWith2Args (node.js:441:9)
4|inwx     |     at process._tickDomainCallback (node.js:396:17)
PM2        | App [inwx] with id [4] and pid [12695], exited with code [1] via signal [SIGINT]

Trying with production API, I looked into the node_modules/inwx/lib/inwx.js file and tried out some console.log messages to get an idea of where the problem is.

function inwx(opts, readyCallback) {
 ...
  this.client = xmlrpc.createClient({ host: opts.host, isSecure: true, path: "/xmlrpc/", cookies: true });

  console.log("inwx.js: so far 1"); // is called successfully

  this.call("account", "login", {user: opts.user, pass: opts.password}, function(response) {
    console.log("inwx.js: connected!"); // never called!!!
    this.connected = true;
    readyCallback.call(this, that);
  });

  return that;
}

inwx.prototype.call = function call(object, method, params, successCallback, errorCallback) {
  if(!object) throw new Error("missing object for xmlrpc call");
  if(!method) throw new Error("missing method for xmlrpc call");

  console.log("inwx.js: so far 2"); // is called successfully

  this.client.methodCall(object + "." + method, [ params ], function(error, response){
    console.log("inwx.js: so far 3"); // never called!!!
    if(error) {

So apparently the callback function of this.client.methodCall is never called.

Tested on fresh Ubuntu 16.04 LTS server (nodejs v4.2.6) and fresh Ubuntu 17.10 desktop (nodejs v6.11.4). freshly installed NodeJS via:

cd ~ && mkdir nodejs_apps && cd nodejs_apps
sudo apt-get install nodejs npm build-essential
sudo ln -s "$(which nodejs)" /usr/bin/node
sudo npm install express
sudo npm install body-parser
sudo npm install request
sudo npm install pm2 -g
sudo npm install inwx
working with pm2 to run the app

Full example app is here: https://pastebin.com/bhdREpNf

@cyril23
Copy link
Author

cyril23 commented Oct 26, 2017

I followed this solution: baalexander/node-xmlrpc#142

and in "node_modules/inwx/lib/inwx.js" I wrote:

this.client = xmlrpc.createSecureClient({url: "https://" + opts.host + "/xmlrpc/", cookies: true});

instead of

this.client = xmlrpc.createClient({ host: opts.host, isSecure: true, path: "/xmlrpc/", cookies: true });

Then everything works.

Please integrate this patch.

@mattes
Copy link
Owner

mattes commented Oct 27, 2017

Can you please open a PR for this? Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants