From ac59a75d27a392d11c92ccea04f2a26229512943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Michael=20O=2E=20Hegg=C3=B8?= <danmichaelo@gmail.com> Date: Sat, 18 Jul 2015 21:07:13 +0200 Subject: [PATCH] [#79] Improve error msg for invalid json response --- mwclient/client.py | 2 +- mwclient/errors.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mwclient/client.py b/mwclient/client.py index d30def1..d00aa1c 100644 --- a/mwclient/client.py +++ b/mwclient/client.py @@ -313,7 +313,7 @@ class Site(object): except ValueError: if res.startswith('MediaWiki API is not enabled for this site.'): raise errors.APIDisabledError - raise ValueError('Could not decode JSON: %s' % res) + raise errors.InvalidResponse(res) def raw_index(self, action, *args, **kwargs): """Sends a call to index.php rather than the API.""" diff --git a/mwclient/errors.py b/mwclient/errors.py index 6540c2d..b428fd1 100644 --- a/mwclient/errors.py +++ b/mwclient/errors.py @@ -56,3 +56,16 @@ class NoSpecifiedEmail(EmailError): class NoWriteApi(MwClientError): pass + + +class InvalidResponse(MwClientError): + + def __init__(self, response_text=None): + self.message = 'Did not get a valid JSON response from the server. Check that ' + \ + 'you used the correct hostname. If you did, the server might ' + \ + 'be wrongly configured or experience temporary problems.' + self.response_text = response_text + MwClientError.__init__(self, self.message, response_text) + + def __str__(self): + return self.message -- GitLab