提交 b5724ea5 编写于 作者: W wangguibao

Elastic CTR

上级 8d5e7b86
...@@ -13,10 +13,14 @@ ...@@ -13,10 +13,14 @@
# limitations under the License. # limitations under the License.
import json import json
import httplib
import sys import sys
import os import os
if sys.version_info[0] == 2:
import httplib
elif sys.version_info[0] == 3:
import http.client
class ElasticCTRAPI(object): class ElasticCTRAPI(object):
def __init__(self, serving_ip, serving_port): def __init__(self, serving_ip, serving_port):
...@@ -34,7 +38,10 @@ class ElasticCTRAPI(object): ...@@ -34,7 +38,10 @@ class ElasticCTRAPI(object):
return 0 return 0
def conn(self, ip, port): 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): def add_instance(self):
feature_slots = [] feature_slots = []
...@@ -67,11 +74,21 @@ class ElasticCTRAPI(object): ...@@ -67,11 +74,21 @@ class ElasticCTRAPI(object):
request_json = json.dumps(req) request_json = json.dumps(req)
try: if sys.version_info[0] == 2:
self._conn.request('POST', "/ElasticCTRPredictionService/inference", try:
request_json, self._conn.request(
{"Content-Type": "application/json"}) 'POST', "/ElasticCTRPredictionService/inference",
response = self._conn.getresponse() request_json, {"Content-Type": "application/json"})
return response.read() response = self._conn.getresponse()
except httplib.HTTPException as e: return response.read()
print e.reason 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册