Main Menu

RPC help

Started by jbutta2k13, July 10, 2014, 07:43:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

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"
  },

xeroc

my issue really is caused by
"authentication" != "Authentication" in the header ...

xeroc

#15
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 ..

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

bitmeat

You need to set RPC user and password both in the config and your client

xeroc

This time I try to connect to the RPC interface using NodeJS

The code:

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:

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:

Unauthorized


As a reference, the curl message that result in the desired about message:

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?

xeroc

Quote from: wackou on July 14, 2014, 02:15:55 PM
Try:
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

HackFisher

Quote from: wackou on July 14, 2014, 02:15:55 PM
Try:
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.

wackou

Try:
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 [url="http://digitalgaia.io"]http://digitalgaia.io[/url]

xeroc

What am I doing wrong:

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[]

xeroc

#7
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 ..

bytemaster

Quote from: 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?

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: [url="http://bytemaster.bitshares.org"]http://bytemaster.bitshares.org[/url]
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.

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?

jbutta2k13

Hack and toast....Thanks alot. I wish I saw those in earlier in the git...

toast

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.

HackFisher

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.

jbutta2k13

#1
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'])