diff --git a/mwclient/client.py b/mwclient/client.py index d30def1af4d6b12a6c1dbbd6971033ad7977c1b2..d00aa1c4f2d7d682a7ce5c0f65dadfa8b2aa3696 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 6540c2d73e2d69da9c16f5c4c4845da517e14124..b428fd1972e433eda0ab25a38912e3f5a9eb9c9c 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