From ccb9d5313822a3f96a275358b86e1661f3b162df Mon Sep 17 00:00:00 2001 From: "M.Hamza Khan" Date: Wed, 10 Mar 2021 13:34:18 +0300 Subject: [PATCH 1/3] fixes https://github.com/opsgenie/opsgenie-python-sdk/issues/48 --- opsgenie_sdk/rest.py | 39 ++++++++++++++++++++------------------- templates/rest.mustache | 39 ++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/opsgenie_sdk/rest.py b/opsgenie_sdk/rest.py index 75fa272..d7c5b16 100644 --- a/opsgenie_sdk/rest.py +++ b/opsgenie_sdk/rest.py @@ -236,27 +236,28 @@ def request(self, method, url, query_params=None, headers=None, # log response body logger.debug("response body: %s", r.data) - data = self.decodeResponse(r.data) http_metrics_request = [('method', method), ('url', url), ('query_params', query_params), ('headers', headers), ('body', body), ('post_params', post_params)] - if "message" not in data: - self.http_metric.build_metric(transaction_id=self.configuration.metrics_transaction_id, - duration=data.get("took"), - resource_path=url, - retry_statistics=copy.deepcopy(self.retrying.statistics), - error=False, - status=r.status, - status_code=r.status, - request=http_metrics_request) - else: - self.http_metric.build_metric(transaction_id=self.configuration.metrics_transaction_id, - duration=data.get("took"), - resource_path=url, - retry_statistics=copy.deepcopy(self.retrying.statistics), - error=True, - status=r.status, - status_code=r.status, - request=http_metrics_request) + + try: + data = self.decodeResponse(r.data) + duration = data.get("took") + if "message" not in data: + error = False + else: + error = True + except: + duration = None + error = True + + self.http_metric.build_metric(transaction_id=self.configuration.metrics_transaction_id, + duration=duration, + resource_path=url, + retry_statistics=copy.deepcopy(self.retrying.statistics), + error=error, + status=r.status, + status_code=r.status, + request=http_metrics_request) should_retry = self.__checkHttpCode__(r.status) if should_retry: diff --git a/templates/rest.mustache b/templates/rest.mustache index 2181f9a..46fe97a 100755 --- a/templates/rest.mustache +++ b/templates/rest.mustache @@ -227,27 +227,28 @@ class RESTClientObject(object): # log response body logger.debug("response body: %s", r.data) - data = self.decodeResponse(r.data) http_metrics_request = [('method', method), ('url', url), ('query_params', query_params), ('headers', headers), ('body', body), ('post_params', post_params)] - if "message" not in data: - self.http_metric.build_metric(transaction_id=self.configuration.metrics_transaction_id, - duration=data.get("took"), - resource_path=url, - retry_statistics=copy.deepcopy(self.retrying.statistics), - error=False, - status=r.status, - status_code=r.status, - request=http_metrics_request) - else: - self.http_metric.build_metric(transaction_id=self.configuration.metrics_transaction_id, - duration=data.get("took"), - resource_path=url, - retry_statistics=copy.deepcopy(self.retrying.statistics), - error=True, - status=r.status, - status_code=r.status, - request=http_metrics_request) + + try: + data = self.decodeResponse(r.data) + duration = data.get("took") + if "message" not in data: + error = False + else: + error = True + except: + duration = None + error = True + + self.http_metric.build_metric(transaction_id=self.configuration.metrics_transaction_id, + duration=duration, + resource_path=url, + retry_statistics=copy.deepcopy(self.retrying.statistics), + error=error, + status=r.status, + status_code=r.status, + request=http_metrics_request) should_retry = self.__checkHttpCode__(r.status) if should_retry: From 92ec5e2c79ed0a51d7dcd1ff1a7488b6c6197630 Mon Sep 17 00:00:00 2001 From: "M.Hamza Khan" Date: Wed, 10 Mar 2021 14:09:52 +0300 Subject: [PATCH 2/3] reflect https://github.com/opsgenie/opsgenie-python-sdk/pull/51 in mustache as well --- templates/api_client.mustache | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/api_client.mustache b/templates/api_client.mustache index 5cbc7cc..779e8af 100755 --- a/templates/api_client.mustache +++ b/templates/api_client.mustache @@ -190,13 +190,13 @@ class ApiClient(object): # perform request and return response try: - response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.retrying.call(fn=self.request, method=method, url=url, - query_params=query_params, - headers=header_params, - post_params=post_params, - body=body, - _preload_content=_preload_content, - _request_timeout=_request_timeout) + response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.retrying(fn=self.request, method=method, url=url, + query_params=query_params, + headers=header_params, + post_params=post_params, + body=body, + _preload_content=_preload_content, + _request_timeout=_request_timeout) except Exception as exception: self._sdk_request_details = { "query_params": query_params, From a937043b98d2c4aafa67ffad95af7294d5d536f6 Mon Sep 17 00:00:00 2001 From: "M.Hamza Khan" Date: Wed, 10 Mar 2021 14:13:06 +0300 Subject: [PATCH 3/3] update version --- README.md | 2 +- opsgenie_sdk/__init__.py | 2 +- opsgenie_sdk/api_client.py | 2 +- opsgenie_sdk/configuration.py | 2 +- scripts/sdk/config.json | 2 +- setup.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f9c9699..1d1e967 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: - API version: 2.0.0 -- Package version: 2.1.2 +- Package version: 2.1.3 - Build package: com.atlassian.opsgenie.codegen.geniepy.GeniepyGenerator For more information, please visit [https://www.opsgenie.com/contact-us](https://www.opsgenie.com/contact-us) diff --git a/opsgenie_sdk/__init__.py b/opsgenie_sdk/__init__.py index 8bf26b5..b30ba61 100644 --- a/opsgenie_sdk/__init__.py +++ b/opsgenie_sdk/__init__.py @@ -168,7 +168,7 @@ from opsgenie_sdk.models.weekday_time_restriction_interval import WeekdayTimeRestrictionInterval from opsgenie_sdk.models.weekday_time_restriction_interval_all_of import WeekdayTimeRestrictionIntervalAllOf -__version__ = "2.1.2" +__version__ = "2.1.3" # import apis into sdk package diff --git a/opsgenie_sdk/api_client.py b/opsgenie_sdk/api_client.py index caf7fbc..245cebe 100644 --- a/opsgenie_sdk/api_client.py +++ b/opsgenie_sdk/api_client.py @@ -88,7 +88,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None, self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = 'opsgenie-sdk-python-2.1.2' + self.user_agent = 'opsgenie-sdk-python-2.1.3' # init metric publishers self.http_metric_publisher = self.rest_client.http_metric diff --git a/opsgenie_sdk/configuration.py b/opsgenie_sdk/configuration.py index 135529f..32466d5 100644 --- a/opsgenie_sdk/configuration.py +++ b/opsgenie_sdk/configuration.py @@ -252,7 +252,7 @@ def to_debug_report(self): "OS: {env}\n"\ "Python Version: {pyversion}\n"\ "Version of the API: 2.0.0\n"\ - "SDK Package Version: 2.1.2".\ + "SDK Package Version: 2.1.3".\ format(env=sys.platform, pyversion=sys.version) def get_host_settings(self): diff --git a/scripts/sdk/config.json b/scripts/sdk/config.json index f3baa11..f77bee7 100644 --- a/scripts/sdk/config.json +++ b/scripts/sdk/config.json @@ -1,7 +1,7 @@ { "packageName": "opsgenie_sdk", "projectName": "opsgenie-sdk", - "packageVersion": "2.1.2", + "packageVersion": "2.1.3", "packageUrl": "https://github.com/opsgenie/opsgenie-python-sdk", "sortParamsByRequiredFlag": "true", "hideGenerationTimestamp": "true", diff --git a/setup.py b/setup.py index 18dcda7..1405640 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ from setuptools import setup, find_packages # noqa: H301 NAME = "opsgenie-sdk" -VERSION = "2.1.2" +VERSION = "2.1.3" # To install the library, run the following # # python setup.py install