This repository was archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
This repository was archived by the owner on May 15, 2024. It is now read-only.
Unauthorized 401 responses throw unnecessary JSONDecodeError #12
Copy link
Copy link
Open
Description
Description
If the account or token is invalid, an expected response with status_code 401 is returned, but the reponse._content is a string Unauthorized, not the expected string {error: <message>}. Thus line 114 content = json.loads(response._content) in jupiterone/client.py will cause json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Reproduction
- Set the account or token in the header to be an invalid value
- Use a breakpoint to verify the response has status_code = 401 and ._content = "Unauthorized"
- Or wrap the call to the client with try-except and verify the Exception has a doc attribute with "Unauthorized"
- Verify that the exception trace stack looks like this:
| File "/usr/local/lib/python3.9/site-packages/jupiterone/client.py", line 203, in query_v1
| return self._cursor_query(
| File "/usr/local/lib/python3.9/site-packages/jupiterone/client.py", line 135, in _cursor_query
| response = self._execute_query(query=CURSOR_QUERY_V1, variables=variables)
| File "/usr/local/lib/python3.9/site-packages/retrying.py", line 49, in wrapped_f
| return Retrying(*dargs, **dkw).call(f, *args, **kw)
| File "/usr/local/lib/python3.9/site-packages/retrying.py", line 206, in call
| return attempt.get(self._wrap_exception)
| File "/usr/local/lib/python3.9/site-packages/retrying.py", line 247, in get
| six.reraise(self.value[0], self.value[1], self.value[2])
| File "/usr/local/lib/python3.9/site-packages/six.py", line 719, in reraise
| raise value
| File "/usr/local/lib/python3.9/site-packages/retrying.py", line 200, in call
| attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
| File "/usr/local/lib/python3.9/site-packages/jupiterone/client.py", line 114, in _execute_query
| content = json.loads(response._content)
| File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
| return _default_decoder.decode(s)
| File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
| obj, end = self.raw_decode(s, idx=_w(s, 0).end())
| File "/usr/local/lib/python3.9/json/decoder.py", line 355, in raw_decode
| raise JSONDecodeError("Expecting value", s, err.value) from None
| json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Environment
- Version: jupiterone 0.2.0
Metadata
Metadata
Assignees
Labels
No labels