Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions bitcoinrpc/authproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def __init__(self, service_url, service_name=None, timeout=HTTP_TIMEOUT):
else:
port = self.__url.port
self.__id_count = 0
authpair = "%s:%s" % (self.__url.username, self.__url.password)
authpair = authpair.encode('utf8')
self.__auth_header = "Basic %s" % base64.b64encode(authpair)
self.__auth_header = ""
if self.__url.username is not None:
authpair = "%s:%s" % (self.__url.username, self.__url.password or "")
authpair = authpair.encode('utf8')
self.__auth_header = "Basic %s" % base64.b64encode(authpair).decode('utf8')
if self.__url.scheme == 'https':
self.__conn = httplib.HTTPSConnection(self.__url.hostname, port,
None, None, False,
Expand All @@ -93,12 +95,7 @@ def __call__(self, *args):
'method': self.__service_name,
'params': args,
'id': self.__id_count})
self.__conn.request('POST', self.__url.path, postdata,
{'Host': self.__url.hostname,
'User-Agent': USER_AGENT,
'Authorization': self.__auth_header,
'Content-type': 'application/json'})

self._request(postdata)
response = self._get_response()
if response['error'] is not None:
raise JSONRPCException(response['error'])
Expand All @@ -108,14 +105,17 @@ def __call__(self, *args):
else:
return response['result']

def _request(self, postdata):
headers = {'Host': self.__url.hostname,
'User-Agent': USER_AGENT,
'Content-type': 'application/json'}
if self.__auth_header:
headers['Authorization'] = self.__auth_header
self.__conn.request('POST', self.__url.path, postdata, headers)

def _batch(self, rpc_call_list):
postdata = json.dumps(list(rpc_call_list))
self.__conn.request('POST', self.__url.path, postdata,
{'Host': self.__url.hostname,
'User-Agent': USER_AGENT,
'Authorization': self.__auth_header,
'Content-type': 'application/json'})

self._request(postdata)
return self._get_response()

def _get_response(self):
Expand Down