You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2019/06/11 19:37:13 UTC

[kibble-scanners] branch master updated: only fetch as json if not errored out.

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble-scanners.git


The following commit(s) were added to refs/heads/master by this push:
     new 963a5d7  only fetch as json if not errored out.
     new 35aeeb0  Merge branch 'master' of github.com:apache/kibble-scanners
963a5d7 is described below

commit 963a5d7f42b124c12a1855ac6a18712b7e1f182c
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 11 21:36:19 2019 +0200

    only fetch as json if not errored out.
    
    We only expect JSON if we hit an okay response code.
    for error responses, we are not interested in the JSON, raise exception
    instead.
---
 src/plugins/utils/jsonapi.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/plugins/utils/jsonapi.py b/src/plugins/utils/jsonapi.py
index 7449e0d..ecda530 100644
--- a/src/plugins/utils/jsonapi.py
+++ b/src/plugins/utils/jsonapi.py
@@ -38,7 +38,6 @@ def get(url, cookie = None, auth = None, token = None, retries = 5):
     if cookie:
         headers["Cookie"] = cookie
     rv = requests.get(url, headers = headers)
-    js = rv.json()
     # Some services may be rate limited. We'll try sleeping it off in 60 second
     # intervals for a max of five minutes, then give up.
     if rv.status_code == 429:
@@ -46,9 +45,9 @@ def get(url, cookie = None, auth = None, token = None, retries = 5):
             time.sleep(60)
             retries -= 1
             return get(url, cookie = cookie, auth = auth, token = token, retries = retries)
-    if rv.status_code != 404:
-        return js
-    return None
+    if rv.status_code < 400:
+        return rv.json()
+    raise Exception("Could not fetch JSON, server responded with status code %u" % rv.status_code)
 
 def gettxt(url, cookie = None, auth = None):
     """ Same as above, but returns as text blob """