diff --git a/elastic-ctr/client/api/python/elasticctr/elastic_ctr_api.py b/elastic-ctr/client/api/python/elasticctr/elastic_ctr_api.py index 5591cfd8851811464ccf86c3cb06606b5dbaf007..a223efcde76c93f58c7239f72f154c31b38b71a4 100644 --- a/elastic-ctr/client/api/python/elasticctr/elastic_ctr_api.py +++ b/elastic-ctr/client/api/python/elasticctr/elastic_ctr_api.py @@ -13,10 +13,14 @@ # limitations under the License. import json -import httplib import sys import os +if sys.version_info[0] == 2: + import httplib +elif sys.version_info[0] == 3: + import http.client + class ElasticCTRAPI(object): def __init__(self, serving_ip, serving_port): @@ -34,7 +38,10 @@ class ElasticCTRAPI(object): return 0 def conn(self, ip, port): - return httplib.HTTPConnection(ip, port) + if sys.version_info[0] == 2: + return httplib.HTTPConnection(ip, port) + elif sys.version_info[0] == 3: + return http.client.HTTPConnection(ip, port) def add_instance(self): feature_slots = [] @@ -67,11 +74,21 @@ class ElasticCTRAPI(object): request_json = json.dumps(req) - try: - self._conn.request('POST', "/ElasticCTRPredictionService/inference", - request_json, - {"Content-Type": "application/json"}) - response = self._conn.getresponse() - return response.read() - except httplib.HTTPException as e: - print e.reason + if sys.version_info[0] == 2: + try: + self._conn.request( + 'POST', "/ElasticCTRPredictionService/inference", + request_json, {"Content-Type": "application/json"}) + response = self._conn.getresponse() + return response.read() + except httplib.HTTPException as e: + print e.reason + elif sys.version_info[0] == 3: + try: + self._conn.request( + 'POST', "/ElasticCTRPredictionService/inference", + request_json, {"Content-Type": "application/json"}) + response = self._conn.getresponse() + return response.read() + except http.clinet.HTTPException as e: + print e.reason