Author Topic: RPC help  (Read 5860 times)

0 Members and 1 Guest are viewing this topic.

Offline mdj

  • Full Member
  • ***
  • Posts: 192
    • View Profile
  • BitShares: mdj
I'm having problems with RPC on v0.8.


$ curl --user user:pass http://127.0.0.1:1776/rpc -X POST -H 'Content-Type: application/json' -d '{"method" : "blockchain_get_account", "params" : ["dev0.theoretical"], "id" : 1}'
curl: (7) Failed connect to 127.0.0.1:1776; Connection refused

Config is:
  "rpc": {
    "enable": true,
    "enable_cache": true,
    "rpc_user": "user",
    "rpc_password": "pass",
    "rpc_endpoint": "127.0.0.1:1775",
    "httpd_endpoint": "127.0.0.1:1776",
    "encrypted_rpc_endpoint": "127.0.0.1:0",
    "encrypted_rpc_wif_key": "",
    "htdocs": "./htdocs"
  },

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
my issue really is caused by
"authentication" != "Authentication" in the header ...

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I figured it out ... the header names are CASE-SENSITIVE!! .. wtf

//edit .. hm sth else is wrong .. using a request (telnet) from the machine where the wallet is running to localhost works ..
using the request from somewhere else connecting to that machine gives me a "Connection reset by peer" ...
however using 'curl' all works fine .. I might screw sth here ..
« Last Edit: July 31, 2014, 09:21:29 am by xeroc »

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Client request has the authorization line which is the http basic auth you are talking about .. the has is removed from my quotes as it would allow login .. second request works .. first dies not

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
You need to set RPC user and password both in the config and your client

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
This time I try to connect to the RPC interface using NodeJS

The code:
Code: [Select]
var request = require('request');
request.post("http://localhost:19988/rpc/", {                                                                                                                             
     json: {"method":"about","params":[],"json-rpc": 2.0,"id":0} },
    function (error, response, body) {
        console.log(body);
    }   

).auth('xeroc', 'secret');

The transmitted message:
Code: [Select]
POST /rpc/ HTTP/1.1
host: localhost:19988
accept: application/json
content-type: application/json
content-length: 50
authorization: Basic authentication-hash
Connection: keep-alive

{"method":"about","params":[],"json-rpc":2,"id":0}


The result:
Code: [Select]
Unauthorized

As a reference, the curl message that result in the desired about message:
Code: [Select]
POST /rpc HTTP/1.1
Authorization: Basic authentication-hash
User-Agent: curl/7.37.0
Host: localhost:19988
Accept: */*
Content-Length: 58
Content-Type: application/x-www-form-urlencoded

{"method":"about", "params": [], "json-rpc": 2.0, "id": 0}

What am I missing?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Try:
Code: [Select]
curl --data '{"method":"about", "params": [], "json-rpc": 2.0, "id": 0}' http://xeroc:***********@localhost:19988/rpc
seems like the "json-rpc" is not required by the bitshares server (although it's more correct to have it). "id" and "params" are both required (you can set "id" to whatever you want, it's user by the server in the reply to identify the request to which it is responding).
Thx .. worked

Offline HackFisher

  • Hero Member
  • *****
  • Posts: 883
    • View Profile
Try:
Code: [Select]
curl --data '{"method":"about", "params": [], "json-rpc": 2.0, "id": 0}' http://xeroc:***********@localhost:19988/rpc
seems like the "json-rpc" is not required by the bitshares server (although it's more correct to have it). "id" and "params" are both required (you can set "id" to whatever you want, it's user by the server in the reply to identify the request to which it is responding).

Some guy told me that the RPC 1.0 not works, but RPC 2.0 work, that might be the reason.
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline wackou

Try:
Code: [Select]
curl --data '{"method":"about", "params": [], "json-rpc": 2.0, "id": 0}' http://xeroc:***********@localhost:19988/rpc
seems like the "json-rpc" is not required by the bitshares server (although it's more correct to have it). "id" and "params" are both required (you can set "id" to whatever you want, it's user by the server in the reply to identify the request to which it is responding).
Please vote for witness wackou! More info at http://digitalgaia.io

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
What am I doing wrong:
Code: [Select]
curl --data '{"method":"about"}' http://xeroc:***********@localhost:19988/rpc
Invalid RPC Request
6 key_not_found_exception: Key Not Found
Key method
    {"key":"method"}
    th_a  variant_object.cpp:90 operator[]

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I see .. gonna check that

edit:
at least I am now getting a Invalid RPC Request. Thanks .. from here I can handle it my self ..
« Last Edit: July 14, 2014, 01:34:51 pm by xeroc »

Offline bytemaster

No idea whats up but when I want to use the RPC interface via python the bitshares_client gets killed because of [out of memory] .. WTF?

There are 2 rpc ports... (one that takes straight JSON and the other that is HTTP based).   If you use the straight JSON and send an HTTP request it triggers a bug that behaves like you describe.
For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
No idea whats up but when I want to use the RPC interface via python the bitshares_client gets killed because of [out of memory] .. WTF?

Offline jbutta2k13

  • Full Member
  • ***
  • Posts: 51
    • View Profile
Hack and toast....Thanks alot. I wish I saw those in earlier in the git...

Offline toast

  • Hero Member
  • *****
  • Posts: 4001
    • View Profile
  • BitShares: nikolai
Looks like you are not querying "host:port/rpc" but just "host:port"
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.