JSON-RPC call to bitcoind error, 403 failed to open stream

2

1

I am trying to make a json-call to a VPS server that hosts my wallet and it is failing with the following error message :

Warning:  fopen(http://user:pass@ip:port): failed to open stream: HTTP request           failed! HTTP/1.1 403 Forbidden
in C:\Users\Owner\Desktop\USBWebServer\root\php\jsonRPCClient.php on line 132

Fatal error:  Uncaught exception 'Exception' with message 'Unable to connect to     http://user:pass@ip:port' in     C:\Users\Owner\Desktop\USBWebServer\root\php\jsonRPCClient.php:140
Stack trace:
#0 C:\Users\Owner\Desktop\USBWebServer\root\php\testrpc.php(15): jsonRPCClient- >__call('getinfo', Array)
#1 C:\Users\Owner\Desktop\USBWebServer\root\php\testrpc.php(15): jsonRPCClient-   >getinfo()
#2 C:\Users\Owner\Desktop\USBWebServer\root\index.php(154): include('C:\Users\Owner\...')
#3 {main}
thrown in C:\Users\Owner\Desktop\USBWebServer\root\php\jsonRPCClient.php on line 140 

i got my JsonRPCClinet.php file from here http://jsonrpcphp.org/code.php?file=jsonRPCClient

my bitcoin.conf file is as follows:

server=1 
daemon=1
listen=1
rpcuser=user
rpcpassword=pass    
rpctimeout=16
rpcallowip=0.0.0.0
rpcport=8332

i am aware that 0.0.0.0 is dangerous , i will change it once i can get things working

i am calling json-rpc using this php code

<?php
  require_once 'jsonRPCClient.php';

  /* Configuration variables for the JSON-RPC server */
    $rpc_host = 'ip';
    $rpc_port = '8332';
    $rpc_user = 'user';
    $rpc_pass = 'pass';

    $btc = new jsonRPCClient('http://' . $rpc_user . ':' . $rpc_pass . '@' . $rpc_host . ':' . $rpc_port);

  echo "<pre>\n";
  print_r($btc->getinfo()); echo "\n";
  echo "Received: ".$btc->getreceivedbylabel("BEkpbpYLpwacchSQFRCL7ZSWw3VwB8k7WN")."\n";
  echo "</pre>";
?> 

additionally i have opened port 8332 on my VPS

can anyone see any reason why this error is occurring, i would greatly appreciate the help

beepbaapboom

Posted 2014-09-10T21:09:05.797

Reputation: 35

Maybe your host is blocking outgoing requests to "non-standard" ports, like 8332? Try 8080 or 443, if they are not reserved by another service. Also try rpcallowip=* instead of 0.0.0.0.George Kimionis 2014-09-10T21:58:34.657

@GeorgeKimionis That's not it - it's failing with a 403 error, which means that it managed to connectNick ODell 2014-09-10T22:49:32.263

@GeorgeKimionis Whoops, I should clarify. I mean that the first suggestion isn't it. The asker should definitely try the second one.Nick ODell 2014-09-10T22:57:26.357

@NickODell we don't really know if it connected to bitcoind, it could be a proxy or even a firewall returning this 403 if packets are filtered.George Kimionis 2014-09-11T00:14:59.063

Answers

4

I just read through the code that handles rpcallowip, and I can tell you that rpcallowip=0.0.0.0 won't work.

If you want to allow from all addresses, you should use

rpcallowip=0.0.0.0/0

(Weirdly, I can't find any code that handles wildcards. I'm going to open an issue on github about it. It looks like either the documentation or the code is wrong.)

Edit: It turns out that wildcard support has been removed.

Nick ODell

Posted 2014-09-10T21:09:05.797

Reputation: 26 536

so i tried 0.0.0.0/0 and * , and i get the exact same error, i also tried a random ip address and i got a different error (not 403 but still could not connect)? does that help in any way?beepbaapboom 2014-09-10T23:44:58.667

Huh, that's odd. Try setting $btc-&gt;debug = true in your program; see if anything enlightening shows up.Nick ODell 2014-09-10T23:54:39.007

if i place it after this line: $btc = new jsonRPCClient('ht...

that gives me this: "Fatal error: Cannot access private property jsonRPCClient::$debug in C:\Users\Owner\Desktop\USBWebServer\root\php\testrpc.php on line 11"

If i change the debug to true in the jsonRPCCLient.php file then it show the same error as the original post
:( – beepbaapboom 2014-09-11T00:00:57.240

@cfxlegion Ah, I misread the code. You should do new jsonRPCClient("http://...", true)Nick ODell 2014-09-11T00:53:17.520

i get this, http://pastebin.com/GGN9WpSK

beepbaapboom 2014-09-11T01:07:23.230

@cfxlegion By 'http://...' I meant put your actual url there.Nick ODell 2014-09-11T01:11:52.137

i did, thats just what the error gave me lol , for the pastebin i only replaced "user" "pass" and "ip"beepbaapboom 2014-09-11T01:15:29.873

Put the quote before the comma, not after the true. See the example I gave above.Nick ODell 2014-09-11T01:17:34.470

@cfxlegion It's best to not post that kind of info :). So, it's definitely an rpcallowip related error, and the config switch I posted should have fixed it. Did you restart your bitcoin client after changing the config setting?Nick ODell 2014-09-11T01:46:22.223

thanks for the heads up, didn't notice i hadnt remove it, :) okay so you're right, it does seem to be some sort of rpcallowip thing, i just put my computers public ip on the allow list and i got a result for "getinfo" , also got some errors but ill figure it out, but it also means that neither "0.0.0.0/0" or "0.0.0.0" or "*" did what they were supposed to do. hmmbeepbaapboom 2014-09-11T01:58:33.883

very important thing missed easily hours spentblockwala 2018-08-09T12:27:13.400

thanks! i was already using this property but for some reason nothing was working with my ipv6 ip until setting it to this!Sonic Soul 2018-08-23T12:14:59.800