Fix the Exception with e.message problem
[modeling/etsicatalog.git] / catalog / pub / Dmaap_lib / dmaap / consumer.py
index 054791c..2b56865 100644 (file)
@@ -1,48 +1,48 @@
-# Copyright (c) 2019, CMCC Technologies Co., Ltd.
-# Licensed under the Apache License, Version 2.0 (the "License")
+# Copyright (c) 2019, CMCC Technologies. Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
-# http://www.apache.org/licenses/LICENSE-2.0
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
 import base64
+import datetime
 import hmac
 import json
 import logging
-import datetime
-import requests
 from hashlib import sha1
 
-from ..pub.exceptions import DmaapClientException
+import requests
 
+from catalog.pub.Dmaap_lib.pub.exceptions import DmaapClientException
+
+requests.packages.urllib3.disable_warnings()
 logger = logging.getLogger(__name__)
 
 
 class ConsumerClient:
-    def __init__(self, host, topic, consumer_group, consumer_id, timeout_ms=-1, limit=-1, filter='',
-                 api_key='', api_secret=''):
-        self.host = host
+    def __init__(self, base_url, topic, consumer_group, consumer_id, timeout_ms=-1, limit=-1, filter=''):
+        self.base_url = base_url
         self.topic = topic
         self.group = consumer_group
         self.comsumer_id = consumer_id
         self.timeout_ms = timeout_ms
         self.limit = limit
         self.filter = filter
-        self.api_key = api_key
-        self.api_secret = api_secret
 
     def set_api_credentials(self, api_key, api_secret):
-
         self.api_key = api_key
         self.api_secret = api_secret
 
     def create_url(self):
-        url = "http://%s/events/%s/%s/%s" % (self.host, self.topic, self.group, self.comsumer_id)
+        url = self.base_url + "/events/%s/%s/%s" % (self.topic, self.group, self.comsumer_id)
         add_url = ""
         if self.timeout_ms > -1:
             add_url += "timeout=%s" % self.timeout_ms
@@ -76,16 +76,17 @@ class ConsumerClient:
             url = self.create_url()
             if self.api_key:
                 headers = self.create_headers()
-                ret = requests.get(url=url, headers=headers)
+                ret = requests.get(url=url, headers=headers, verify=False)
             else:
                 ret = requests.get(url)
             logger.info("Status code is %s, detail is %s.", ret.status_code, ret.json())
             if ret.status_code != 200:
-                raise DmaapClientException('Call dmaap failed. Status code is %s, detail is %s.' % (ret.status_code, ret.json()))
+                raise DmaapClientException(
+                    'Call dmaap failed. Status code is %s, detail is %s.' % (ret.status_code, ret.json()))
             data = ret.json()
             for msg in data:
                 msg = json.loads(msg)
                 msgs.append(msg)
             return msgs
         except Exception as e:
-            raise DmaapClientException(e.message)
+            raise DmaapClientException(str(e))