mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Add request timeout to JSONRPC backend
This commit is contained in:
parent
64149f6323
commit
010408dcf9
8 changed files with 27 additions and 13 deletions
|
@ -1,3 +1,3 @@
|
|||
from . import address, account, daemon, wallet, numbers, prio, wordlists, seed
|
||||
|
||||
__version__ = '0.5.2'
|
||||
__version__ = '0.5.3'
|
||||
|
|
|
@ -22,8 +22,10 @@ class JSONRPCDaemon(object):
|
|||
:param host: host name or IP
|
||||
:param port: port number
|
||||
:param path: path for JSON RPC requests (should not be changed)
|
||||
:param timeout: request timeout
|
||||
"""
|
||||
def __init__(self, protocol='http', host='127.0.0.1', port=18081, path='/json_rpc', user='', password=''):
|
||||
def __init__(self, protocol='http', host='127.0.0.1', port=18081, path='/json_rpc',
|
||||
user='', password='', timeout=30):
|
||||
self.url = '{protocol}://{host}:{port}'.format(
|
||||
protocol=protocol,
|
||||
host=host,
|
||||
|
@ -31,6 +33,7 @@ class JSONRPCDaemon(object):
|
|||
_log.debug("JSONRPC daemon backend URL: {url}".format(url=self.url))
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.timeout = timeout
|
||||
|
||||
def info(self):
|
||||
info = self.raw_jsonrpc_request('get_info')
|
||||
|
@ -62,7 +65,8 @@ class JSONRPCDaemon(object):
|
|||
_log.debug(u"Request: {path}\nData: {data}".format(
|
||||
path=path,
|
||||
data=json.dumps(data, indent=2, sort_keys=True)))
|
||||
rsp = requests.post(self.url + path, headers=hdr, data=json.dumps(data))
|
||||
rsp = requests.post(
|
||||
self.url + path, headers=hdr, data=json.dumps(data), timeout=self.timeout)
|
||||
if rsp.status_code != 200:
|
||||
raise RPCError("Invalid HTTP status {code} for path {path}.".format(
|
||||
code=rsp.status_code,
|
||||
|
@ -80,7 +84,9 @@ class JSONRPCDaemon(object):
|
|||
method=method,
|
||||
params=json.dumps(params, indent=2, sort_keys=True)))
|
||||
auth = requests.auth.HTTPDigestAuth(self.user, self.password)
|
||||
rsp = requests.post(self.url + '/json_rpc', headers=hdr, data=json.dumps(data), auth=auth)
|
||||
rsp = requests.post(
|
||||
self.url + '/json_rpc', headers=hdr, data=json.dumps(data), auth=auth,
|
||||
timeout=self.timeout)
|
||||
if rsp.status_code == 401:
|
||||
raise Unauthorized("401 Unauthorized. Invalid RPC user name or password.")
|
||||
elif rsp.status_code != 200:
|
||||
|
@ -112,11 +118,13 @@ class JSONRPCWallet(object):
|
|||
:param path: path for JSON RPC requests (should not be changed)
|
||||
:param user: username to authenticate with over RPC
|
||||
:param password: password to authenticate with over RPC
|
||||
:param timeout: request timeout
|
||||
"""
|
||||
_master_address = None
|
||||
_addresses = None
|
||||
|
||||
def __init__(self, protocol='http', host='127.0.0.1', port=18088, path='/json_rpc', user='', password=''):
|
||||
def __init__(self, protocol='http', host='127.0.0.1', port=18088, path='/json_rpc',
|
||||
user='', password='', timeout=30):
|
||||
self.url = '{protocol}://{host}:{port}/json_rpc'.format(
|
||||
protocol=protocol,
|
||||
host=host,
|
||||
|
@ -124,6 +132,7 @@ class JSONRPCWallet(object):
|
|||
_log.debug("JSONRPC wallet backend URL: {url}".format(url=self.url))
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.timeout = timeout
|
||||
_log.debug("JSONRPC wallet backend auth: '{user}'/'{stars}'".format(
|
||||
user=user, stars=('*' * len(password)) if password else ''))
|
||||
|
||||
|
@ -311,7 +320,8 @@ class JSONRPCWallet(object):
|
|||
method=method,
|
||||
params=json.dumps(params, indent=2, sort_keys=True)))
|
||||
auth = requests.auth.HTTPDigestAuth(self.user, self.password)
|
||||
rsp = requests.post(self.url, headers=hdr, data=json.dumps(data), auth=auth)
|
||||
rsp = requests.post(
|
||||
self.url, headers=hdr, data=json.dumps(data), auth=auth, timeout=self.timeout)
|
||||
if rsp.status_code == 401:
|
||||
raise Unauthorized("401 Unauthorized. Invalid RPC user name or password.")
|
||||
elif rsp.status_code != 200:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue