fiatjaf / bitcoin-requests Goto Github PK
View Code? Open in Web Editor NEWSimplest Bitcoin Core RPC interface.
License: Other
Simplest Bitcoin Core RPC interface.
License: Other
Hi, if you are interested, I am using the library with an interface like this that automatically finds credentials:
def __init__(self, datadir='~/.bitcoin', rpcurl='127.0.0.1', rpcuser=None, rpcpassword=None, rpcport=None):
if '://' in rpcurl:
dummy, rpcurl = rpcurl.split('://', 1)
if '/' in rpcurl:
rpcurl, dummy = rpcurl.split('/', 1)
if '@' in rpcurl:
if rpcuser is not None:
raise Exception('user specified in rpcurl and parameter list')
rpcuser, rpcurl = rpcurl.split('@', 1)
if ':' in rpcuser:
if rpcpassword is not None:
raise Exception('password specified in rpcurl and parameter list')
rpcuser, rpcpassword = rpcuser.split(':', 1)
if ':' in rpcurl:
if rpcport is not None:
raise DatacoinException('port specified in rpcurl and parameter list')
rpcurl, rpcport = rpcurl.split(':', 1)
rpcurl = 'http://{}'.format(rpcurl)
if rpcport is not None:
rpcurl += ':{}'.format(rpcport)
if rpcpassword is None and rpcuser is None:
datadir = os.path.expanduser(datadir)
cookiefn = os.path.join(datadir, '.cookie')
if os.path.exists(cookiefn):
with open(cookiefn) as cookiefile:
rpcuser, rpcpassword = cookiefile.read().split(':', 1)
Empty responses (e.g. rpc.gethelp('nonexistent')
or rpc.nonexistent()
) presently raise a json decoding error. it would be nice to raise a non-json error or simply return None.
Having some trouble getting calls to work properly. Any idea what I'm doing wrong? Bitcoin Core is running in background.
>>> username = '<my_username>'
>>> password = '<password>'
>>> rpc = BitcoinRPC('http://127.0.0.1:8332', username, password)
>>> rpc
<bitcoin_requests.bitcoin.BitcoinRPC object at 0x0000029F23B13B20>
>>> blockhash='000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254'
>>> block = rpc.getblock(blockhash)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\bitcoin_requests\bitcoin.py", line 30, in call
resp = json.loads(v, parse_float=decimal.Decimal)
File "C:\Python39\lib\json\__init__.py", line 359, in loads
return cls(**kw).decode(s)
File "C:\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.