thefactory / marathon-python

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

_do_request can raise JSONDecodeError when it means to raise InternalServerError #202

Closed EvanKrall closed 7 years ago

EvanKrall commented 7 years ago

When Marathon returns a 502, it spits out some HTML instead of JSON:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 502 </title>
</head>
<body>
<h2>HTTP ERROR: 502</h2>
<p>Problem accessing /v2/apps. Reason:
<pre>    Failed to successfully establish a connection to the leader.</pre></p>
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.z-SNAPSHOT</a><hr/>
</body>
</html>

This makes creating an InternalServerError object fail with JSONDecodeError:

Traceback (most recent call last):
...
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/paasta_tools/bounce_lib.py", line 133, in create_marathon_app
    client.create_app(app_id, MarathonApp(**config))
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/marathon/client.py", line 149, in create_app
    response = self._do_request('POST', '/v2/apps', data=data)
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/marathon/client.py", line 94, in _do_request
    raise InternalServerError(response)
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/marathon/exceptions.py", line 13, in __init__
    content = response.json()
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/requests/models.py", line 819, in json
    return json.loads(self.text, **kwargs)
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/simplejson/__init__.py", line 516, in loads
    return _default_decoder.decode(s)
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/simplejson/decoder.py", line 374, in decode
    obj, end = self.raw_decode(s)
  File "/opt/venvs/paasta-tools/local/lib/python2.7/site-packages/simplejson/decoder.py", line 404, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
EvanKrall commented 7 years ago

Oh, it looks like this was fixed since the version we're running: https://github.com/thefactory/marathon-python/commit/faebe66e8fb0c7a43a86b6c3c14380d856ab0e88