BitShares Forum

Main => General Discussion => Topic started by: jbutta2k13 on July 10, 2014, 07:43:17 pm

Title: RPC help
Post by: jbutta2k13 on July 10, 2014, 07:43:17 pm
I have the rpc server started but I cannot connect using python and requests....can someone tell me why I am getting this error.  I have no problems conneting python to http server..


ConnectionError: HTTPConnectionPool(host='localhost', port=18332): Max retries exceeded with url: / (Caused by <class 'socket.error'>: [Errno 10061] No connection could be made because the target machine actively refused it)

config.json rpc info

"rpc": {
    "enable": true,
    "rpc_user": "user",
    "rpc_password": "1234",
    "rpc_endpoint": "localhost:18832",
    "httpd_endpoint": "localhost:8801",
    "htdocs": "./htdocs"



python code snippet....

serverURL = 'http://' + rpc_user + ':' + rpc_password + '@localhost:' + str(rpcPort)
headers = {'content-type': 'application/json'}
payload = json.dumps({"method": 'get_info', "jsonrpc": "2.0"})
response = requests.get(serverURL, headers=headers, data=payload)
print(response.json()['result'])

Title: Re: RPC help
Post by: HackFisher on July 11, 2014, 12:52:18 am
Have a look at this example, good luck

https://github.com/Bitsuperlab/Bitshares_optools/blob/master/batch_enable_delegates.py (https://github.com/Bitsuperlab/Bitshares_optools/blob/master/batch_enable_delegates.py)
Title: Re: RPC help
Post by: toast on July 11, 2014, 12:54:39 am
Looks like you are not querying "host:port/rpc" but just "host:port"
Title: Re: RPC help
Post by: jbutta2k13 on July 11, 2014, 12:36:59 pm
Hack and toast....Thanks alot. I wish I saw those in earlier in the git...
Title: Re: RPC help
Post by: xeroc on July 14, 2014, 01:26:36 pm
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?
Title: Re: RPC help
Post by: bytemaster on July 14, 2014, 01:30:11 pm
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.
Title: Re: RPC help
Post by: xeroc on July 14, 2014, 01:32:30 pm
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 ..
Title: Re: RPC help
Post by: xeroc on July 14, 2014, 01:50:25 pm
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[]
Title: Re: RPC help
Post by: wackou on July 14, 2014, 02:15:55 pm
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).
Title: Re: RPC help
Post by: HackFisher on July 14, 2014, 11:11:07 pm
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.
Title: Re: RPC help
Post by: xeroc on July 15, 2014, 04:32:57 am
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
Title: Re: RPC help
Post by: xeroc on July 30, 2014, 08:46:16 pm
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?
Title: Re: RPC help
Post by: bitmeat on July 30, 2014, 08:51:56 pm
You need to set RPC user and password both in the config and your client
Title: Re: RPC help
Post by: xeroc on July 30, 2014, 11:02:56 pm
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
Title: Re: RPC help
Post by: xeroc on July 31, 2014, 08:59:27 am
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 ..
Title: Re: RPC help
Post by: xeroc on July 31, 2014, 12:05:31 pm
my issue really is caused by
"authentication" != "Authentication" in the header ...
Title: Re: RPC help
Post by: mdj on April 03, 2015, 01:32:00 pm
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"
  },