Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError when 401 Unauthorized is received #22

Closed
iven opened this issue Mar 9, 2015 · 3 comments
Closed

ValueError when 401 Unauthorized is received #22

iven opened this issue Mar 9, 2015 · 3 comments

Comments

@iven
Copy link
Contributor

iven commented Mar 9, 2015

In this case, the return value is not JSON:

>>> c = MarathonClient('http://xulijian-mesos-online001-cqdx:8080', 'root', '111')
>>> c.list_apps()
ERROR:marathon:Got HTTP 401: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing /v2/apps. Reason:
<pre>    Unauthorized</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>




















</body>
</html>

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/iven/.local/share/virtualenvs/guardro/lib/python2.7/site-packages/marathon/client.py", line 134, in list_apps
    response = self._do_request('GET', '/v2/apps', params=params)
  File "/home/iven/.local/share/virtualenvs/guardro/lib/python2.7/site-packages/marathon/client.py", line 80, in _do_request
    raise MarathonHttpError(response)
  File "/home/iven/.local/share/virtualenvs/guardro/lib/python2.7/site-packages/marathon/exceptions.py", line 11, in __init__
    content = response.json()
  File "/home/iven/.local/share/virtualenvs/guardro/lib/python2.7/site-packages/requests/models.py", line 799, in json
    return json.loads(self.text, **kwargs)
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
@solarkennedy
Copy link
Contributor

Yea, probably better for the request to check for a non 200 and raise a normal python exception

@hlerebours
Copy link
Contributor

@iven do we agree that this issue is fixed by #178? With your example I now get:

>>> c.list_apps()
Traceback (most recent call last):
  [...]
MarathonHttpError: MarathonHttpError: HTTP 401 returned with message, "Unauthorized"

@iven
Copy link
Contributor Author

iven commented Mar 22, 2017

@hlerebours Sorry, I'm not using Marathon these days, but I think you can trust your test result. 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants