diff --git a/bitcoinrpc/authproxy.py b/bitcoinrpc/authproxy.py index 8c56aaf..2914477 100644 --- a/bitcoinrpc/authproxy.py +++ b/bitcoinrpc/authproxy.py @@ -67,9 +67,17 @@ def __init__(self, service_url, service_name=None, timeout=HTTP_TIMEOUT, connect 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) + (user, passwd) = (self.__url.username, self.__url.password) + try: + user = user.encode('utf8') + except AttributeError: + pass + try: + passwd = passwd.encode('utf8') + except AttributeError: + pass + authpair = user + b':' + passwd + self.__auth_header = b'Basic ' + base64.b64encode(authpair) if connection: # Callables re-use the connection of the original proxy