I am starting to use a basic implementation of Bitcoin JSON RPC (dzhuvinov library), and I am getting a strange result. Here is my code:

public static void main(String[] args)
    URL serverURL = null;

    final String rpcuser ="user";
      final String rpcpassword ="pass";

      Authenticator.setDefault(new Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
              return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
    try {
        serverURL = new URL("");

    } catch (MalformedURLException e) {
     JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
     String method = "getinfo";
     int requestID = 0;
     JSONRPC2Request request = new JSONRPC2Request(method, requestID);
     JSONRPC2Response response = null;
     try {
             response = mySession.send(request);

     } catch (JSONRPC2SessionException e) {
     if (response.indicatesSuccess())

And the response I am getting is:

Invalid JSON-RPC 2.0 response

Just to note - when executing this Python script:

access = jsonrpc.ServiceProxy("http://user:[email protected]:18332/")
print access.getinfo()

I get a proper results.

What might be causing this problem and how should I go about fixing it?

  • Could you attach a packet sniffer to both of them?
    – Nick ODell
    Feb 10, 2013 at 0:03
  • @NickODell Tried to, but failed. Although I figured out what the problem is some other way.
    – ThePiachu
    Feb 10, 2013 at 8:49

1 Answer 1


As it turns out, the library I am using does not like JSON responses that contain both the field "error" and "response", even if the "error" field is set to null. I have already notified the creator of the library to possibly fix that issue and I have patched it myself as well:

In the private Map<String,Object> parseJSONObject(final String jsonString) function, one needs to add this at the end:

    Map<String,Object> answer = (Map<String,Object>)json;

    if (answer.containsKey("error")){
        if (answer.get("error")==null){
    if (answer.containsKey("result")){
        if (answer.get("result")==null){

    return answer;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.