I wrote up a script that uses this repo:
https://github.com/laanwj/bitcoin-pythonI know it's an older repo but I like it. Anyway, it works great most of the time. But sometimes my script just can't connect to my bitcoind -server for some inexplicable reason. Does anyone have a guess as to what that reason might be? I just upgraded to the latest version of core but the seemingly random issue persists.
class BitcoinConnection(object):
"""
A BitcoinConnection object defines a connection to a bitcoin server.
It is a thin wrapper around a JSON-RPC API connection.
Arguments to constructor:
- *user* -- Authenticate as user.
- *password* -- Authentication password.
- *host* -- Bitcoin JSON-RPC host.
- *port* -- Bitcoin JSON-RPC port.
"""
def __init__(self, user, password, host='localhost', port=8332,
use_https=False):
"""
Create a new bitcoin server connection.
"""
url = 'http{s}://{user}:{password}@{host}:{port}/'.format(
s='s' if use_https else '',
user=user, password=password, host=host, port=port)
self.url = url
self.proxy = AuthServiceProxy(url, exception_wrapper=wrap_exception)
And I am using this method:
def getrawchangeaddress(self, account=None):
"""
Returns a new bitcoin raw change address for properly handling change.
"""
return self.proxy.getrawchangeaddress()
Bitcoind shows this in the log:
2017-03-14 08:33:36 connect() to 71.239.98.166:8333 failed after select(): Connection refused (61)