How can I connect to RPC

+1 vote

I've tried to use Savoir to connect to the RPC client and try to make a simple getinfo call, but I keep getting a connection error with a bad status line. I've done some reading and I know this has something to do with the http call basically failing and not returning a response.

I haven't got a password set, and I can't see how to do this anywhere in the guides or Q&A, besides being told that I should put it in the multichain.conf file, but even when I do this the cal still fails. I've also tried using the python and cur examples here: https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#Command_line_.28cURL.29, but none of these work.

My code is:

from Savoir import Savoir
import requests
import json

rpcuser = 'manager'
rpcpasswd = 'pass'
rpchost = 'localhost'
rpcport = '6451'
chainname = 'intrdr_chain_1'

api = Savoir(rpcuser, rpcpasswd, rpchost, rpcport, chainname)


def create_transaction(rule):
    api.getinfo()
    print 'done'
    print api.getinfo()

And I get the following traceback:

  File "rpc_script.py", line 15, in create_transaction
    api.getinfo()
  File "/webapps/blocknet/local/lib/python2.7/site-packages/Savoir/Savoir.py", line 58, in __call__
    r = requests.post(url, data=encoded, headers=self.__headers)
  File "/webapps/blocknet/local/lib/python2.7/site-packages/requests/api.py", line 107, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/webapps/blocknet/local/lib/python2.7/site-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File "/webapps/blocknet/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/webapps/blocknet/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/webapps/blocknet/local/lib/python2.7/site-packages/requests/adapters.py", line 426, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))

 

 Could it be possible my configuration settings are wrong? is it possible to not require the password, or is there another way to do this? I've basically resorted to making terminal calls from python as a subprocess which was the only way I could get it to work (which of course basically just circumvents the RPC alltogether).

asked Mar 11, 2017 by anonymous

1 Answer

0 votes
 
Best answer

You need to enter the username/password from multichain.conf into your Python code. Also ensure the node is running on the same computer as the Python script (for now – you can change this later) and that the rpcport is correct, i.e. not the peer-to-peer port used by nodes to talk to each other.

answered Mar 11, 2017 by MultiChain
Thanks so much for the speedy response! Got it working now, I had 2 issues:

- I was setting my username and password in the conf file in the /.multichain folder as opposed to the specific sub-directory for my chain
- I was trying to connect on the port used for peer-to-peer
Great - glad it's sorted now.
...