Skip to content
This repository was archived by the owner on Dec 18, 2021. It is now read-only.
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
17 changes: 16 additions & 1 deletion phoenixdb/avatica/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.encode()).decode()

response = self._post_request(body, headers)
response_body = response.read()
Expand Down