Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created January 10, 2014 22:56
Show Gist options
  • Select an option

  • Save ryancdotorg/8364317 to your computer and use it in GitHub Desktop.

Select an option

Save ryancdotorg/8364317 to your computer and use it in GitHub Desktop.
from bitcoinrpc.authproxy import AuthServiceProxy
def asp_from_config(filename):
rpcport = '8332'
rpcconn = '127.0.0.1'
rpcuser = None
rpcpass = None
with open(filename, 'r') as f:
for line in f:
(key, val) = line.rstrip().replace(' ', '').split('=')
if key == 'rpcuser':
rpcuser = val
elif key == 'rpcpassword':
rpcpass = val
elif key == 'rpcport':
rpcport = val
elif key == 'rpcconnect':
rpcconn = val
f.close()
if rpcuser is not None and rpcpass is not None:
rpcurl = 'http://%s:%s@%s:%s' % (rpcuser, rpcpass, rpcconn, rpcport)
print_stderr('RPC server: %s' % rpcurl)
return AuthServiceProxy(rpcurl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment