[mod] show real exception for easier debugging
This commit is contained in:
pare
857968f34e
commit
1d76bc150a
S'han modificat 1 arxius amb 23 adicions i 11 eliminacions
|
@ -56,8 +56,10 @@ class Mastodon:
|
||||||
request_data['redirect_uris'] = 'urn:ietf:wg:oauth:2.0:oob';
|
request_data['redirect_uris'] = 'urn:ietf:wg:oauth:2.0:oob';
|
||||||
|
|
||||||
response = requests.post(api_base_url + '/api/v1/apps', data = request_data, timeout = request_timeout).json()
|
response = requests.post(api_base_url + '/api/v1/apps', data = request_data, timeout = request_timeout).json()
|
||||||
except:
|
except Exception as e:
|
||||||
raise MastodonNetworkError("Could not complete request.")
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise MastodonNetworkError("Could not complete request: %s" % e)
|
||||||
|
|
||||||
if to_file != None:
|
if to_file != None:
|
||||||
with open(to_file, 'w') as secret_file:
|
with open(to_file, 'w') as secret_file:
|
||||||
|
@ -142,8 +144,10 @@ class Mastodon:
|
||||||
try:
|
try:
|
||||||
response = self.__api_request('POST', '/oauth/token', params, do_ratelimiting = False)
|
response = self.__api_request('POST', '/oauth/token', params, do_ratelimiting = False)
|
||||||
self.access_token = response['access_token']
|
self.access_token = response['access_token']
|
||||||
except:
|
except Exception as e:
|
||||||
raise MastodonIllegalArgumentError('Invalid user name, password or scopes.')
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise MastodonIllegalArgumentError('Invalid user name, password or scopes: %s' % e)
|
||||||
|
|
||||||
requested_scopes = " ".join(sorted(scopes))
|
requested_scopes = " ".join(sorted(scopes))
|
||||||
received_scopes = " ".join(sorted(response["scope"].split(" ")))
|
received_scopes = " ".join(sorted(response["scope"].split(" ")))
|
||||||
|
@ -355,8 +359,10 @@ class Mastodon:
|
||||||
media_ids_proper.append(media_id["id"])
|
media_ids_proper.append(media_id["id"])
|
||||||
else:
|
else:
|
||||||
media_ids_proper.append(media_id)
|
media_ids_proper.append(media_id)
|
||||||
except:
|
except Exception as e:
|
||||||
raise MastodonIllegalArgumentError("Invalid media dict.")
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise MastodonIllegalArgumentError("Invalid media dict: %s" % e)
|
||||||
|
|
||||||
params_initial["media_ids"] = media_ids_proper
|
params_initial["media_ids"] = media_ids_proper
|
||||||
|
|
||||||
|
@ -544,8 +550,10 @@ class Mastodon:
|
||||||
|
|
||||||
if method == 'DELETE':
|
if method == 'DELETE':
|
||||||
response_object = requests.delete(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout)
|
response_object = requests.delete(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout)
|
||||||
except:
|
except Exception as e:
|
||||||
raise MastodonNetworkError("Could not complete request.")
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise MastodonNetworkError("Could not complete request: %s" % e)
|
||||||
|
|
||||||
if response_object == None:
|
if response_object == None:
|
||||||
raise MastodonIllegalArgumentError("Illegal request.")
|
raise MastodonIllegalArgumentError("Illegal request.")
|
||||||
|
@ -565,7 +573,9 @@ class Mastodon:
|
||||||
try:
|
try:
|
||||||
response = response_object.json()
|
response = response_object.json()
|
||||||
except:
|
except:
|
||||||
raise MastodonAPIError("Could not parse response as JSON, respose code was " + str(response_object.status_code))
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise MastodonAPIError("Could not parse response as JSON, respose code was %s, bad json content was '%s'" % (response_object.status_code, response_object.content))
|
||||||
|
|
||||||
# Handle rate limiting
|
# Handle rate limiting
|
||||||
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
||||||
|
@ -582,8 +592,10 @@ class Mastodon:
|
||||||
server_time_diff = time.time() - server_time
|
server_time_diff = time.time() - server_time
|
||||||
self.ratelimit_reset += server_time_diff
|
self.ratelimit_reset += server_time_diff
|
||||||
self.ratelimit_lastcall = time.time()
|
self.ratelimit_lastcall = time.time()
|
||||||
except:
|
except Exception as e:
|
||||||
raise MastodonRatelimitError("Rate limit time calculations failed.")
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e)
|
||||||
|
|
||||||
if "error" in response and response["error"] == "Throttled":
|
if "error" in response and response["error"] == "Throttled":
|
||||||
if self.ratelimit_method == "throw":
|
if self.ratelimit_method == "throw":
|
||||||
|
|
Loading…
Referencia en una nova incidència