diff options
| author | Scott Bahling <sbahling@suse.de> | 2015-08-06 17:16:48 +0200 |
|---|---|---|
| committer | Scott Bahling <sbahling@suse.de> | 2015-08-06 17:16:48 +0200 |
| commit | 4fe7816a5d6d9b1d9ee171c62c6111b95a925f1f (patch) | |
| tree | 4386ee3e501fc866de28b0c2f33666f849972685 /obsapi/core.py | |
| parent | 1c18d4ee5a127431e2d31bae6bc060545d776548 (diff) | |
| download | obsapi-0.0.4.tar.gz obsapi-0.0.4.tar.xz obsapi-0.0.4.zip | |
Add some robustness to http connectionsobsapi-0.0.4
- Add a retry loop. Shouldn't be required, but sometimes api.suse.com
fails with authentication and a second retry works.
- Add verify_ssl option to turn off SSL verification. Needed when
facing temporary SSL certificate issues on the api server.
Diffstat (limited to 'obsapi/core.py')
| -rw-r--r-- | obsapi/core.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/obsapi/core.py b/obsapi/core.py index 174af85..74b8997 100644 --- a/obsapi/core.py +++ b/obsapi/core.py @@ -132,6 +132,8 @@ class ObsApi(object): self.apiurl = apiurl or DEFAULTAPIURL self.__get_auth() self._response = None + self.retries = 3 + self.verify_ssl = True def __get_auth(self): conf = {} @@ -149,9 +151,18 @@ class ObsApi(object): self.auth = None def __api_get(self, api, payload=None): - url = '{0}/{1}'.format(self.apiurl, api) - r = requests.get(url, auth=self.auth, params=payload) - self._response = r + + for attempt in range(self.retries): + url = '{0}/{1}'.format(self.apiurl, api) + r = requests.get(url, + auth=self.auth, + params=payload, + verify=self.verify_ssl) + self._response = r + if self.success: + return r + print("Failed: %s" % self.response) + print("retry: %s" % (attempt + 1)) return r @@ -169,6 +180,7 @@ class ObsApi(object): def get_xml(self, api, payload=None): r = self.__api_get(api, payload) if not self.success: + print self.response return self.default_xml return r.text |
