Bitcoin Forum

Bitcoin => Project Development => Topic started by: Alex Beckenham on April 25, 2011, 04:31:55 PM



Title: JSON error, help please
Post by: Alex Beckenham on April 25, 2011, 04:31:55 PM
Hi,

I've been trying to debug something for 2 hours now, so frustrating.

exception 'Exception' with message 'Unable to connect to http://myusername:mypassword@127.0.0.1:8332/'

Any reason why it wouldn't be able to connect even though my username and password are correct?

It throws this error when I try to do
Code:
$bitcoin -> sendfrom(PROGRAM_NAME,$pay_out_address,0.01);

Also I've double-checked the logs and the 3 args I'm sending to this function are completely valid.

Thanks


Title: Re: JSON error, help please
Post by: fabianhjr on April 25, 2011, 04:43:53 PM
Can you please give the full raw error?
Also, a little bit more of your code would help to see how you connected.


Title: Re: JSON error, help please
Post by: Alex Beckenham on April 25, 2011, 04:54:21 PM
The weird thing is I can easily do $bitcoin->validateaddress('biwoejfiwjefiwojeifow');  with no problem; it connects to the wallet and returns valid info.

Code:
Array
(
    [isvalid] => 1
    [address] => biwoejfiwjefiwojeifow
    [ismine] =>
)

However just a couple of lines after that when I try to do the send it says it can't connect.

Code:
try {
$pay_out_address_details=$bitcoin->validateaddress($new_user['pay_out_address']);
echo '<pre>';
print_r($pay_out_address_details);
echo '</pre>';
}
catch (Exception $e) {
echo $e.'<br>';
die("<p>Server error! Please contact the admin.</p>");
}
It gets past that bit, but immediately after it is this, which it breaks on:

Code:
if ($pay_out_address_details['isvalid']==1) {
//add_to_log('Valid address... sending '.$new_user['pay_out_amount'].' BTC...');
$sendamt=number_format($new_user['pay_out_amount'],2,'.','');
if ($sendamt<=1000) {

try {
$bitcoin->sendfrom(PROGRAM_NAME,$new_user['pay_out_address'],$sendamt);
}
catch (Exception $e) {
echo $e.'<br>';
die("<p>Server error! Please contact the admin.</p>");
}

//add_to_log('...sent successfully.');
}
}

Note the add_to_log statements have been commented out.


Title: Re: JSON error, help please
Post by: Alex Beckenham on April 25, 2011, 05:28:21 PM
Code:
Array
(
    [isvalid] => 1
    [address] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    [ismine] =>
)

exception 'Exception' with message 'Unable to connect to http://xxxxxxxxxxxxx:yyyyyyyyyyyyy@127.0.0.1:8332/' in /web/sites/me/_shared/jsonRPCClient.php:140 Stack trace: #0 [internal function]: jsonRPCClient->__call('sendfrom', Array) #1 /web/sites/me/mydomain.com/public_html/_run_test9.php(109): jsonRPCClient->sendfrom('My Site', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', '0.46') #2 {main}

Server error! Please contact the admin.

NFI.

I might need to order a new monitor soon coz I'm about to punch this one after 3 hours.



Title: Re: JSON error, help please
Post by: BioMike on April 25, 2011, 05:31:20 PM
My experience with the jsonRPCClient was that it was as buggy as hell. I would look into that (not your code).


Title: Re: JSON error, help please
Post by: Alex Beckenham on April 25, 2011, 05:40:59 PM
Well, I just tested that... exactly the same server, same daemon, same wallet, different domain name and it was able to send 100% fine.

Code:
	define('INC','../inc/');
require_once(INC.'jsonRPCClient.php');
 
$bitcoin = new jsonRPCClient('http://xxxxxxxxxxxx:yyyyyyyyyyyyy@127.0.0.1:8332/');


$bitcoin->sendfrom('My Site','xxxxxxxxxxxxxxxxxxxxxxx',1);

 
echo "<pre>\n";
print_r($bitcoin->getinfo());

$listaccounts=$bitcoin->listaccounts();
print_r($listaccounts);

(Username and password are exactly the same in both scripts).

I'll try putting this stupido script onto this other domain...


Title: Re: JSON error, help please
Post by: Alex Beckenham on April 25, 2011, 06:22:06 PM
Wow, problem solved after only 4 hours.

Code:
$bitcoin->sendfrom('My Site','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',0.04);  //works with literals
$bitcoin->sendfrom(SITE_NAME,'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',0.04); //works with constant and 2 literals
$bitcoin->sendfrom(SITE_NAME,$ref_details['pay_out_address'],0.04); //works with constant, var and 1 literal
$bitcoin->sendfrom(SITE_NAME,$ref_details['pay_out_address'],$sendamt); //COMPLETELY FUBAR TOOK 4 HOURS OF MY LIFE AWAY SON OF A BITCH I HATE PROGRAMMING
$bitcoin->sendfrom(SITE_NAME,$ref_details['pay_out_address'],(float)$sendamt); //works with constant and 2 vars if 3rd is type cast

I really do love programming though, honestly.

Tags: PHP, JSON, RPC, Unable to connect, float, string, amount, type cast, error, fubar