Bitcoin Forum
August 27, 2015, 07:23:58 PM *
News: New! Latest stable version of Bitcoin Core: 0.11.0 [Torrent]
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Unable to connect using JSON-RPC  (Read 3827 times)
davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW

Ignore
October 20, 2010, 02:12:15 PM
 #1

Hello all,

I'd really be thankful for some help in getting my JSON RPC client to actually get to talk to my bitcoin daemon.
Basically, I've been actively trying different JSON client with pretty much the same results... 401 Unauthorized...

I've also tried the Curl based example from the docs which is working as a charm, so I'm really wondering wth i'm doing wrong...

Nothing helpful found in the debug.log (I can re-symlink it to /dev/null now Cheesy )

Would anyone be kind enough to have a little look at my code and/or give me a couple of pointers ?

Thank you very much





irb(main):009:0> client = JsonRPC::Client.new("http://admin:passsword@localhost:8332/")
=> #<JsonRPC::Client:0x7ffe29900978 @address=#<Addressable::URI:0x3fff14c8028c URI:http://admin:passsword@localhost:8332/>>
irb(main):010:0> client.request 'getbalance', {}
JSON::ParserError: 705: unexpected token at '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<TITLE>Error</TITLE>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
</HEAD>
<BODY><H1>401 Unauthorized.</H1></BODY>
</HTML>
'
        from /usr/lib/ruby/gems/1.8/gems/json-1.4.6/lib/json/common.rb:146:in `parse'
        from /usr/lib/ruby/gems/1.8/gems/json-1.4.6/lib/json/common.rb:146:in `parse'
        from /usr/lib/ruby/gems/1.8/gems/jsonrpc-0.9.2/lib/jsonrpc.rb:20:in `request'
        from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
        from /usr/lib/ruby/1.8/net/http.rb:440:in `start'
        from /usr/lib/ruby/gems/1.8/gems/jsonrpc-0.9.2/lib/jsonrpc.rb:19:in `request'
        from (irb):10



Contents of my bitcoin.conf
rpcpassword=password
rpcuser=admin

1440703438
Hero Member
*
Offline Offline

Posts: 1440703438

View Profile Personal Message (Offline)

Ignore
1440703438
Reply with quote  #2

1440703438
Report to moderator
1440703438
Hero Member
*
Offline Offline

Posts: 1440703438

View Profile Personal Message (Offline)

Ignore
1440703438
Reply with quote  #2

1440703438
Report to moderator
1440703438
Hero Member
*
Offline Offline

Posts: 1440703438

View Profile Personal Message (Offline)

Ignore
1440703438
Reply with quote  #2

1440703438
Report to moderator
7 Different Live Games
30 Live tables
Why look for fortune elsewhere? 200+ BTC Jackpot
400+ Slot Games
New Provably Fair BlackJack!
Unbeatable Loyalty Program!

Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1440703438
Hero Member
*
Offline Offline

Posts: 1440703438

View Profile Personal Message (Offline)

Ignore
1440703438
Reply with quote  #2

1440703438
Report to moderator
1440703438
Hero Member
*
Offline Offline

Posts: 1440703438

View Profile Personal Message (Offline)

Ignore
1440703438
Reply with quote  #2

1440703438
Report to moderator
1440703438
Hero Member
*
Offline Offline

Posts: 1440703438

View Profile Personal Message (Offline)

Ignore
1440703438
Reply with quote  #2

1440703438
Report to moderator
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW

Ignore
October 20, 2010, 07:16:30 PM
 #2

Ruby (or your Ruby JSON-RPC library) isn't setting the Authorization: HTTP header from the username:password in the URL.

I don't know anything about Ruby, but Mr. Google might be able to shed some light-- you need to either set the Authorization: header yourself to do the HTTP Basic authentication (I seem to recall some Ruby code on the Wikipedia page about HTTP Basic Authentication) or, in some languages/frameworks there's a way of setting up a 'context' for HTTP connections so the authentication happens properly.

How often do you get the chance to work on a potentially world-changing project?
davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW

Ignore
October 20, 2010, 10:55:08 PM
 #3

Fixed, there were a couple of things wrong, one of them being effectively lame credentials handling.
Thanks for the pointer.

Will publish a ruby gem pretty soon with a Json RPC client and some more useful bitcoin related stuff.

Until then if someone is interested in the actual code : http://github.com/davout/bitcoin-bank.git

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!