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 help  (Read 1591 times)

0 Members and 1 Guest are viewing this topic.

Offline jbutta2k13

  • Full Member
  • ***
  • Posts: 51
    • View Profile
RPC help
« 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'])

« Last Edit: July 10, 2014, 07:58:35 PM by jbutta2k13 »

Offline HackFisher

  • Hero Member
  • *****
  • Posts: 883
    • View Profile
Re: RPC help
« Reply #1 on: July 11, 2014, 12:52:18 AM »
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 toast

Re: RPC help
« Reply #2 on: July 11, 2014, 12:54:39 AM »
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.

Offline jbutta2k13

  • Full Member
  • ***
  • Posts: 51
    • View Profile
Re: RPC help
« Reply #3 on: July 11, 2014, 12:36:59 PM »
Hack and toast....Thanks alot. I wish I saw those in earlier in the git...

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #4 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?
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline bytemaster

Re: RPC help
« Reply #5 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.
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: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #6 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 ..
« Last Edit: July 14, 2014, 01:34:51 PM by xeroc »
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #7 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[]
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline wackou

Re: RPC help
« Reply #8 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).
Please vote for witness wackou! More info at http://digitalgaia.io

Offline HackFisher

  • Hero Member
  • *****
  • Posts: 883
    • View Profile
Re: RPC help
« Reply #9 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.
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: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #10 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
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #11 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?
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline bitmeat

  • Hero Member
  • *****
  • Posts: 1116
    • View Profile
Re: RPC help
« Reply #12 on: July 30, 2014, 08:51:56 PM »
You need to set RPC user and password both in the config and your client

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #13 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
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12336
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BTS: xeroc
  • GitHub: xeroc
Re: RPC help
« Reply #14 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 ..
« Last Edit: July 31, 2014, 09:21:29 AM by xeroc »
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

 

Google+