python-bitcoinrpc

raw JSON →
1.0 verified Fri May 01 auth: no python maintenance

Enhanced version of python-jsonrpc for use with Bitcoin. This library provides a simple RPC client to interact with Bitcoin Core's JSON-RPC API. Current version is 1.0, but the project is in maintenance mode and has known issues with modern Python and Bitcoin Core versions.

pip install python-bitcoinrpc
error ImportError: No module named bitcoinrpc.authproxy
cause The package is not installed or installed in wrong environment.
fix
Run 'pip install python-bitcoinrpc' and verify import path: from bitcoinrpc.authproxy import AuthServiceProxy
error AttributeError: 'NoneType' object has no attribute 'group'
cause The library's regex parsing of the RPC response failed, often due to malformed response or unexpected characters.
fix
Ensure the RPC server returns valid JSON. Check that the URL is correct and the server is running.
error Error: unable to connect to RPC server
cause The RPC URL is incorrect or server is not reachable.
fix
Verify RPC_HOST, RPC_PORT, and credentials. Test with curl: curl --user user:pass --data-binary '{"jsonrpc":"1.0","id":"curl","method":"getblockchaininfo","params":[]}' http://127.0.0.1:8332
breaking The library expects the RPC URL to contain the username and password directly in the URL (e.g., http://user:pass@host:port). Using a pre-authenticated URL or passing separate credentials to AuthServiceProxy is not supported.
fix Construct the URL as 'http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}'
deprecated python-bitcoinrpc is largely unmaintained and does not support Python 3.7+. It uses deprecated 'cookielib' and other Python 2 idioms. Consider using 'bitcoinrpc' (Python 3 fork) or direct requests to call JSON-RPC.
fix Switch to the maintained fork 'python-bitcoinrpc' (different package) or use requests library directly.
gotcha The library does not support SSL/TLS by default. Connecting over plain HTTP may expose credentials. Use a local RPC connection or tunnel if needed.
fix Ensure RPC server is on localhost or use a reverse proxy with HTTPS.

Connect to a Bitcoin Core RPC server using environment variables for credentials.

from bitcoinrpc.authproxy import AuthServiceProxy

rpc_user = os.environ.get('RPC_USER', 'user')
rpc_password = os.environ.get('RPC_PASSWORD', 'pass')
rpc_host = os.environ.get('RPC_HOST', '127.0.0.1')
rpc_port = os.environ.get('RPC_PORT', '8332')

# Note: python-bitcoinrpc expects URL with credentials embedded
url = f'http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}'
proxy = AuthServiceProxy(url)

# Test connection
print(proxy.getblockchaininfo())