diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 558d1c1..efbe89d 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -95,8 +95,17 @@ class Mastodon: | |||
95 | params['grant_type'] = 'password' | 95 | params['grant_type'] = 'password' |
96 | params['scope'] = " ".join(scopes) | 96 | params['scope'] = " ".join(scopes) |
97 | 97 | ||
98 | response = self.__api_request('POST', '/oauth/token', params) | 98 | try: |
99 | self.access_token = response['access_token'] | 99 | response = self.__api_request('POST', '/oauth/token', params) |
100 | self.access_token = response['access_token'] | ||
101 | except: | ||
102 | raise ValueError('Invalid user name, password or scopes.') | ||
103 | |||
104 | requested_scopes = " ".join(scopes) | ||
105 | received_scopes = " ".join(sorted(response["scopes"].split(" "))) | ||
106 | |||
107 | if requested_scopes != received_scopes: | ||
108 | raise ValueError('Granted scopes "' + received_scopes + '" differ from requested scopes "' + requested_scopes + '".') | ||
100 | 109 | ||
101 | if to_file != None: | 110 | if to_file != None: |
102 | with open(to_file, 'w') as token_file: | 111 | with open(to_file, 'w') as token_file: |
@@ -330,7 +339,12 @@ class Mastodon: | |||
330 | if response.status_code == 500: | 339 | if response.status_code == 500: |
331 | raise IOError('General API problem.') | 340 | raise IOError('General API problem.') |
332 | 341 | ||
333 | return response.json() | 342 | try: |
343 | response = response.json() | ||
344 | except: | ||
345 | raise ValueError("Could not parse response as JSON, respose code was " + str(response.status_code)) | ||
346 | |||
347 | return response | ||
334 | 348 | ||
335 | def __generate_params(self, params, exclude = []): | 349 | def __generate_params(self, params, exclude = []): |
336 | """ | 350 | """ |