"Forbidden" error when connecting to JSON-RPC API

+1 vote

Hi,

MultiChain version: MultiChain Core Daemon build 1.0 alpha 21 protocol 10005

I'm trying to connect to the JSON-RPC API. For that, I use a Python script. default-rpc-port is set to 8346 in params.dat

    config = file2dic(".multichain/icsv-chain/multichain.conf")
    url = "http://" + config["rpcuser"] + ":" + config["rpcpassword"] + "@127.0.0.1:8346/"
    headers = {
        'content-type': 'content-type: application/json'
    }
    payload = {
        "jsonrpc": "1.0", 
        "id": 0, 
        "method": "getinfo", 
        "params": [] 
    }
    response = requests.post(url, data=json.dumps(payload), headers=headers)

Response is 403. Any ideas?

Edit1: The generated URL: http://multichainrpc:AXsiEahZe19QgpCwZwFJRL327SqcKrFaVv1FfpeQGij3@127.0.0.1:8346/

Edit2: Also tried:
{
        "jsonrpc": "1.0", 
        "id": 0, 
        "method": "icsv-chain getinfo", 
        "params": [] 
    }

Edit3: Also tried:

{
        "jsonrpc": "1.0", 
        "id": "1", 
        "method": "getinfo", 
        "chain_name": "icsv-chain",
        "params": [] 
    }

Edit4: I have isolated the problem. I am actually using Docker to run multichaind on my Mac. Inside of the container, this works: 

curl -X POST -H "Content-Type: text/plain" -H "Authorization: Basic bXVsdGljaGFpbnJwYzpBWHNpRWFoWmUxOVFncEN3WndGSlJMMzI3U3FjS3JGYVZ2MUZmcGVRR2lqMw==" -H "Cache-Control: no-cache" -H "Postman-Token: 1ac4e084-e8c8-10a2-f290-fd24fd13d1e0" -d '{
        "jsonrpc": "1.0", 
        "id": "1", 
        "method": "getinfo", 
        "chain_name": "icsv-chain",
        "params": [] 
    }' "http://127.0.0.1:8346/"

Outside of the container, this does not work. I did my port mapping like this:

 

docker run \

    --name=multichain-node \

    -p 8346:8346 \

    -p 8347:8347 \

    -v $(pwd)/.multichain:/root/.multichain \

    -it multichain-node multichaind $PEER -rpcallowip=0.0.0.0

But is still does not work. Any ideas?

asked Aug 4, 2016 by MitchK
edited Aug 5, 2016 by MitchK
Is multichain-cli able to connect to the node? That's a way to check the JSON-API server is responding correctly, to narrow the problem down to the Python code.
Yes, the CLI works. Also see the URL that I am calling.

1 Answer

0 votes

Are you sure the requests Python library supports usernames and passwords in URLs, for HTTP Basic Authentication?

answered Aug 5, 2016 by MultiChain
Yes, it does. I also tried it using auth=HTTPBasicAuth(...). I think I have isolated the problem, see Edit4
Great - thanks for posting your own answer!
Hi! Sorry, misunderstanding. Still having the problem :( In my original post you see how I start the Docker container. Are there any other 403 checks in the daemon than with the credentials?
Yes, it will also be the source IP address for the request. By default the daemon only accepts requests from localhost (127.0.0.1) and this won't be how requests appear from outside the Docker container. Search this Q&A for the rpcallowip parameter.
Adding to this question, where can I find logs for the rpc requests? do we have any configurable parameter to enable this logging? or there aren't any log messages added for that.?
multichain-cli logs rpc requests in ~/.multichain/. cli_history/<chain-name>.log

It can be disabled by specifying -saveclilog=0 multichain-cli runtime parameter.

multichaind will log all rpc requests in debug.log if you start it with -debug=mcapi
...