aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon/Mastodon.py')
-rw-r--r--mastodon/Mastodon.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index b9ab05b..12ceb1d 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -56,8 +56,10 @@ class Mastodon:
56 request_data['redirect_uris'] = 'urn:ietf:wg:oauth:2.0:oob'; 56 request_data['redirect_uris'] = 'urn:ietf:wg:oauth:2.0:oob';
57 57
58 response = requests.post(api_base_url + '/api/v1/apps', data = request_data, timeout = request_timeout).json() 58 response = requests.post(api_base_url + '/api/v1/apps', data = request_data, timeout = request_timeout).json()
59 except: 59 except Exception as e:
60 raise MastodonNetworkError("Could not complete request.") 60 import traceback
61 traceback.print_exc()
62 raise MastodonNetworkError("Could not complete request: %s" % e)
61 63
62 if to_file != None: 64 if to_file != None:
63 with open(to_file, 'w') as secret_file: 65 with open(to_file, 'w') as secret_file:
@@ -142,8 +144,10 @@ class Mastodon:
142 try: 144 try:
143 response = self.__api_request('POST', '/oauth/token', params, do_ratelimiting = False) 145 response = self.__api_request('POST', '/oauth/token', params, do_ratelimiting = False)
144 self.access_token = response['access_token'] 146 self.access_token = response['access_token']
145 except: 147 except Exception as e:
146 raise MastodonIllegalArgumentError('Invalid user name, password or scopes.') 148 import traceback
149 traceback.print_exc()
150 raise MastodonIllegalArgumentError('Invalid user name, password or scopes: %s' % e)
147 151
148 requested_scopes = " ".join(sorted(scopes)) 152 requested_scopes = " ".join(sorted(scopes))
149 received_scopes = " ".join(sorted(response["scope"].split(" "))) 153 received_scopes = " ".join(sorted(response["scope"].split(" ")))
@@ -355,8 +359,10 @@ class Mastodon:
355 media_ids_proper.append(media_id["id"]) 359 media_ids_proper.append(media_id["id"])
356 else: 360 else:
357 media_ids_proper.append(media_id) 361 media_ids_proper.append(media_id)
358 except: 362 except Exception as e:
359 raise MastodonIllegalArgumentError("Invalid media dict.") 363 import traceback
364 traceback.print_exc()
365 raise MastodonIllegalArgumentError("Invalid media dict: %s" % e)
360 366
361 params_initial["media_ids"] = media_ids_proper 367 params_initial["media_ids"] = media_ids_proper
362 368
@@ -544,8 +550,10 @@ class Mastodon:
544 550
545 if method == 'DELETE': 551 if method == 'DELETE':
546 response_object = requests.delete(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) 552 response_object = requests.delete(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout)
547 except: 553 except Exception as e:
548 raise MastodonNetworkError("Could not complete request.") 554 import traceback
555 traceback.print_exc()
556 raise MastodonNetworkError("Could not complete request: %s" % e)
549 557
550 if response_object == None: 558 if response_object == None:
551 raise MastodonIllegalArgumentError("Illegal request.") 559 raise MastodonIllegalArgumentError("Illegal request.")
@@ -565,7 +573,9 @@ class Mastodon:
565 try: 573 try:
566 response = response_object.json() 574 response = response_object.json()
567 except: 575 except:
568 raise MastodonAPIError("Could not parse response as JSON, respose code was " + str(response_object.status_code)) 576 import traceback
577 traceback.print_exc()
578 raise MastodonAPIError("Could not parse response as JSON, respose code was %s, bad json content was '%s'" % (response_object.status_code, response_object.content))
569 579
570 # Handle rate limiting 580 # Handle rate limiting
571 if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting: 581 if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
@@ -582,8 +592,10 @@ class Mastodon:
582 server_time_diff = time.time() - server_time 592 server_time_diff = time.time() - server_time
583 self.ratelimit_reset += server_time_diff 593 self.ratelimit_reset += server_time_diff
584 self.ratelimit_lastcall = time.time() 594 self.ratelimit_lastcall = time.time()
585 except: 595 except Exception as e:
586 raise MastodonRatelimitError("Rate limit time calculations failed.") 596 import traceback
597 traceback.print_exc()
598 raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e)
587 599
588 if "error" in response and response["error"] == "Throttled": 600 if "error" in response and response["error"] == "Throttled":
589 if self.ratelimit_method == "throw": 601 if self.ratelimit_method == "throw":
Powered by cgit v1.2.3 (git 2.41.0)