From d74ad9336ecd3dea3728b9cbbc611e1c56404e28 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Thu, 8 Sep 2022 15:27:15 +0200 Subject: Ignore unreachable ogServers Otherwise, ogCP crashes trying to connect to unreachable ogServers. --- ogcp/og_server.py | 9 ++++++--- ogcp/views.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'ogcp') diff --git a/ogcp/og_server.py b/ogcp/og_server.py index 07dcb2b..0f542ff 100644 --- a/ogcp/og_server.py +++ b/ogcp/og_server.py @@ -23,9 +23,12 @@ class OGServer: self.HEADERS = {'Authorization' : self.api_token} def get(self, path, payload=None): - r = requests.get(f'{self.URL}{path}', - headers=self.HEADERS, - json=payload) + try: + r = requests.get(f'{self.URL}{path}', + headers=self.HEADERS, + json=payload) + except requests.exceptions.ConnectionError: + return None return r def post(self, path, payload): diff --git a/ogcp/views.py b/ogcp/views.py index 16b4fba..84bf0e1 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -201,6 +201,8 @@ def multi_request(method, uri, payload=None): else: raise Exception('Invalid method, use get or post') + if not r: + continue response['server'] = server response['json'] = r.json() responses.append(response) -- cgit v1.2.3-18-g5258