From 3a0ee47df2171ac244446eb195d62ab79700c0e7 Mon Sep 17 00:00:00 2001 From: Matteo Lodi <30625432+mlodic@users.noreply.github.com> Date: Wed, 14 Apr 2021 16:28:55 +0200 Subject: [PATCH] adding timeout option to pypssl GET --- client/pypssl/api.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/pypssl/api.py b/client/pypssl/api.py index 4de1495..9e235c2 100644 --- a/client/pypssl/api.py +++ b/client/pypssl/api.py @@ -26,8 +26,8 @@ class PyPSSL(object): # No authentication defined. pass - def _query(self, url): - response = self.session.get(url) + def _query(self, url, timeout=None): + response = self.session.get(url, timeout=timeout) try: return response.json() except: @@ -47,7 +47,7 @@ class PyPSSL(object): return {'error': 'Incorrect format'} return None - def query(self, q): + def query(self, q, timeout=None): check = self._check_IP(q) if check is not None: return check @@ -55,19 +55,19 @@ class PyPSSL(object): path = 'pssl/query/{}'.format(q) else: path = 'v2pssl/query/{}'.format(q) - return self._query(urljoin(self.base_url, path)) + return self._query(urljoin(self.base_url, path), timeout=timeout) - def query_cert(self, q): + def query_cert(self, q, timeout=None): if self.api_version != 2: return {'error': 'Only available in API v2'} path = 'v2pssl/cquery/{}'.format(q) - return self._query(urljoin(self.base_url, path)) + return self._query(urljoin(self.base_url, path), timeout=timeout) - def fetch_cert(self, q, make_datetime=True): + def fetch_cert(self, q, make_datetime=True, timeout=None): if self.api_version != 2: return {'error': 'Only available in API v2'} path = 'v2pssl/cfetch/{}'.format(q) - response = self._query(urljoin(self.base_url, path)) + response = self._query(urljoin(self.base_url, path), timeout=timeout) if response.get('error') or not make_datetime: return response # create python datetime, doesn't return a json object