diff options
Diffstat (limited to '')
-rw-r--r-- | python.d/python_modules/bases/FrameworkServices/UrlService.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/python.d/python_modules/bases/FrameworkServices/UrlService.py b/python.d/python_modules/bases/FrameworkServices/UrlService.py index 0941ab168..bb340ba3b 100644 --- a/python.d/python_modules/bases/FrameworkServices/UrlService.py +++ b/python.d/python_modules/bases/FrameworkServices/UrlService.py @@ -75,20 +75,31 @@ class UrlService(SimpleService): :return: str """ try: - url = url or self.url - manager = manager or self._manager - response = manager.request(method='GET', - url=url, - timeout=self.request_timeout, - retries=1, - headers=manager.headers) + status, data = self._get_raw_data_with_status(url, manager) except (urllib3.exceptions.HTTPError, TypeError, AttributeError) as error: self.error('Url: {url}. Error: {error}'.format(url=url, error=error)) return None - if response.status == 200: - return response.data.decode() - self.debug('Url: {url}. Http response status code: {code}'.format(url=url, code=response.status)) - return None + + if status == 200: + return data.decode() + else: + self.debug('Url: {url}. Http response status code: {code}'.format(url=url, code=status)) + return None + + def _get_raw_data_with_status(self, url=None, manager=None, retries=1, redirect=True): + """ + Get status and response body content from http request. Does not catch exceptions + :return: int, str + """ + url = url or self.url + manager = manager or self._manager + response = manager.request(method='GET', + url=url, + timeout=self.request_timeout, + retries=retries, + headers=manager.headers, + redirect=redirect) + return response.status, response.data def check(self): """ |