thefactory / marathon-python

Python client library for Mesos Marathon's REST API
MIT License
197 stars 193 forks source link

ValueError when 401 Unauthorized is received #22

Closed iven closed 7 years ago

iven commented 9 years ago

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 commented 8 years ago

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

hlerebours commented 7 years ago

@iven do we agree that this issue is fixed by https://github.com/thefactory/marathon-python/pull/178? With your example I now get:

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

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