jgarzik / python-bitcoinrpc

Python interface to bitcoin's JSON-RPC API
GNU Lesser General Public License v2.1
642 stars 307 forks source link

parse RPC errors into exception object and provide better output handling #43

Closed nikcub closed 9 years ago

nikcub commented 9 years ago

parse JSON-RPC error object into code and message and provide string and object casting.

example:

try:
    block_hashes = rpc_connection.batch_(commands)
    blocks = rpc_connection.batch_([ [ "getblocks", h ] for h in block_hashes ])
    block_times = [ block["time"] for block in blocks ]
    print(block_times)
except JSONRPCException, e:
    print "Error: %s" % e
    print e.code
    print e.message

backwards compatible.