From 11e4813bd19bb79d7d13d6b156f21fc128993eb2 Mon Sep 17 00:00:00 2001 From: murata100 <39039774+murata100@users.noreply.github.com> Date: Wed, 17 Apr 2019 18:26:46 +0900 Subject: [PATCH 1/2] Support Azure HDInsight --- phoenixdb/avatica/client.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/phoenixdb/avatica/client.py b/phoenixdb/avatica/client.py index 5e8bc3d..8a79fd9 100644 --- a/phoenixdb/avatica/client.py +++ b/phoenixdb/avatica/client.py @@ -22,12 +22,18 @@ import time from phoenixdb import errors from phoenixdb.avatica.proto import requests_pb2, common_pb2, responses_pb2 +import base64 try: import httplib except ImportError: import http.client as httplib +try: + from urllib import unquote # Python 2.X +except ImportError: + from urllib.parse import unquote # Python 3+ + try: import urlparse except ImportError: @@ -152,7 +158,12 @@ def connect(self): """Opens a HTTP connection to the RPC server.""" logger.debug("Opening connection to %s:%s", self.url.hostname, self.url.port) try: - self.connection = httplib.HTTPConnection(self.url.hostname, self.url.port) + connectionClass = None + if self.url.scheme == 'https': + connectionClass = httplib.HTTPSConnection + else: + connectionClass = httplib.HTTPConnection + self.connection = connectionClass(self.url.hostname, self.url.port) self.connection.connect() except (httplib.HTTPException, socket.error) as e: raise errors.InterfaceError('Unable to connect to the specified service', e) @@ -203,6 +214,10 @@ def _apply(self, request_data, expected_response_type=None): message.wrapped_message = request_data.SerializeToString() body = message.SerializeToString() headers = {'content-type': 'application/x-google-protobuf'} + find_atmark = self.url.netloc.find('@') + if find_atmark >= 0: + authstr = unquote(self.url.netloc[:find_atmark]) + headers['Authorization'] = 'Basic ' + base64.b64encode(authstr) response = self._post_request(body, headers) response_body = response.read() From d1afb49883178471319cddddce9e1c98e0a0cdae Mon Sep 17 00:00:00 2001 From: murata100 <39039774+murata100@users.noreply.github.com> Date: Wed, 17 Apr 2019 18:37:36 +0900 Subject: [PATCH 2/2] Compatible with python3 --- phoenixdb/avatica/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phoenixdb/avatica/client.py b/phoenixdb/avatica/client.py index 8a79fd9..b70ea89 100644 --- a/phoenixdb/avatica/client.py +++ b/phoenixdb/avatica/client.py @@ -217,7 +217,7 @@ def _apply(self, request_data, expected_response_type=None): find_atmark = self.url.netloc.find('@') if find_atmark >= 0: authstr = unquote(self.url.netloc[:find_atmark]) - headers['Authorization'] = 'Basic ' + base64.b64encode(authstr) + headers['Authorization'] = 'Basic ' + base64.b64encode(authstr.encode()).decode() response = self._post_request(body, headers) response_body = response.read()