Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: RPC Error: 400 when trying to talk to bitshares_client through RPC  (Read 449 times)

Offline 8bit

  • Full Member
  • ***
  • Posts: 56
    • View Profile

I'm trying to get the BTSX client to talk to a node.js app using RPC. The client starts the RPC server fine:

Code: [Select]
$ ./bitshares_client --server --httpport 9989
Loading blockchain from "/home/eightbit/.BitSharesX/chain"
Loading config "/home/eightbit/.BitSharesX/config.json"
Starting JSON RPC server on port 50022 (localhost only)
Starting HTTP JSON RPC server on port 9989 (localhost only)

But when I try to run my node.js server, I get:

Quote
Client: TODO Status Code: 400

Which refers to:

Quote from: wikipedia
4xx Client Error
The 4xx class of status code is intended for cases in which the client seems to have errored. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents should display any included entity to the user.

400 Bad Request
The request cannot be fulfilled due to bad syntax.

Here is the RPC section of my config.json:

Code: [Select]
  "rpc": {
    "enable": true,
    "rpc_user": "test",
    "rpc_password": "test",
    "rpc_endpoint": "127.0.0.1:0",
    "httpd_endpoint": "127.0.0.1:0",
    "htdocs": "/"
  },

and here is the code I'm using in node:

Code: [Select]
DELBID.rpc = require('node-json-rpc');

DELBID.rpc.options = {
// int port of rpc server, default 5080 for http or 5433 for https
port: 9989,
// string domain name or ip of rpc server, default '127.0.0.1'
host: '127.0.0.1',
//username
login: "test",
//password
hash: "test"
// string with default path, default '/'
path: '/',
// boolean false to turn rpc checks off, default true
strict: true,
};

// Create a server object with options
DELBID.rpc.client = new DELBID.rpc.Client(DELBID.rpc.options);

//run blockchain_get_config in the wallet and print the results to the console
DELBID.rpc.client.call({"jsonrpc": "2.0", "method": "blockchain_get_config", "params": []}, function(err, res) {
if (err) { console.log(err); } else {
console.log(res);
}
});

I'm not exactly sure how the node.js 'path' and the bitshares config 'htdocs' elements function, so I feel the issue might stem from them. Also, perhaps the rpc method names are different from the hooks in the interactive client? If they are, are they documented anywhere?
« Last Edit: July 27, 2014, 06:48:02 AM by 8bit »
Code: [Select]
wallet_approve_delegate eightbitA VOTE FOR EIGHTBIT IS A VOTE FOR CRUDE DICK ART

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #1 on: July 27, 2014, 09:52:21 PM »
Haven't tried in Node JS, however here is the code I used to connect via Python:

https://bitsharestalk.org/index.php?topic=4125.msg84087#msg84087


Offline toast

Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #2 on: July 27, 2014, 09:53:39 PM »

path: '/',
->
path: '/rpc',
Do not use this post as information for making any important decisions. The only agreements I ever make are informal and non-binding. Take the same precautions as when dealing with a compromised account, scammer, sockpuppet, etc.

Offline 8bit

  • Full Member
  • ***
  • Posts: 56
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #3 on: July 27, 2014, 10:14:47 PM »

path: '/',
->
path: '/rpc',

Thanks for the response, toast. Am I doing this right?:

wallet config:

Code: [Select]
  "rpc": {
    "enable": true,
    "rpc_user": "test",
    "rpc_password": "test",
    "rpc_endpoint": "127.0.0.1:0",
    "httpd_endpoint": "127.0.0.1:0",
    "path": "/"
  },

node.js config:

Code: [Select]

DELBID.rpc = require('node-json-rpc');
DELBID.rpc.options = {
port: 9989,
host: '127.0.0.1',
path: '/rpc',
strict: true,
login: "test",
hash: "test"
};

DELBID.rpc.client = new DELBID.rpc.Client(DELBID.rpc.options);
DELBID.rpc.client.call({"jsonrpc": "2.0", "method": "blockchain_get_config", "params": []}, function(err, res) {
if (err) { console.log(err); } else {
console.log(res);
}
});

I'm still getting a 400 error...

Haven't tried in Node JS, however here is the code I used to connect via Python:

https://bitsharestalk.org/index.php?topic=4125.msg84087#msg84087

Thanks! Would you mind posting the rpc section of your wallet config as well?
« Last Edit: July 27, 2014, 10:20:17 PM by 8bit »
Code: [Select]
wallet_approve_delegate eightbitA VOTE FOR EIGHTBIT IS A VOTE FOR CRUDE DICK ART

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #4 on: July 27, 2014, 10:23:22 PM »
Is your wallet unlocked? Perhaps the command you are trying requires the wallet to be unlocked.

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #5 on: July 27, 2014, 10:25:09 PM »
    "rpc_endpoint": "0.0.0.0:0",
    "httpd_endpoint": "0.0.0.0:0",
    "htdocs": "./htdocs"

I have this in mine. But I call it with a param to set --httpport

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #6 on: July 27, 2014, 10:25:43 PM »
I don't have this:

 "path": "/"

Offline 8bit

  • Full Member
  • ***
  • Posts: 56
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #7 on: July 27, 2014, 10:28:45 PM »
Is your wallet unlocked? Perhaps the command you are trying requires the wallet to be unlocked.

Yes, I keep my wallet unlocked because I run delegates. And I'm only trying to grab blockcount and blockchain config. Not sure if it requires the wallet to be open, but either way, it is.

Thanks for the thought, though

Quote
   "rpc_endpoint": "0.0.0.0:0",
    "httpd_endpoint": "0.0.0.0:0",
    "htdocs": "./htdocs"

tried that, and still getting the same error... do you have anything located in your wallet's ./htdocs folder? Is that where you put your python stuff?
Code: [Select]
wallet_approve_delegate eightbitA VOTE FOR EIGHTBIT IS A VOTE FOR CRUDE DICK ART

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
Re: RPC Error: 400 when trying to talk to bitshares_client through RPC
« Reply #8 on: July 27, 2014, 11:29:51 PM »
I'm not even using the same machine. I'm connecting remotely to a box, that is firewalled so only I can connect to it.

 

Google+