clean up methods handling, let Requests worry about methods
This commit is contained in:
pare
b18b6f201b
commit
5bc1706aa2
S'han modificat 1 arxius amb 4 adicions i 19 eliminacions
|
@ -1024,29 +1024,14 @@ class Mastodon:
|
||||||
while not request_complete:
|
while not request_complete:
|
||||||
request_complete = True
|
request_complete = True
|
||||||
|
|
||||||
response_object = None
|
|
||||||
try:
|
try:
|
||||||
if method == 'GET':
|
response_object = requests.request(
|
||||||
response_object = requests.get(self.api_base_url + endpoint, params=params,
|
method, self.api_base_url + endpoint, params=params,
|
||||||
headers=headers, files=files,
|
headers=headers, files=files,
|
||||||
timeout=self.request_timeout)
|
timeout=self.request_timeout)
|
||||||
if method == 'POST':
|
|
||||||
response_object = requests.post(self.api_base_url + endpoint, data=params, headers=headers,
|
|
||||||
files=files, timeout=self.request_timeout)
|
|
||||||
|
|
||||||
if method == 'PATCH':
|
|
||||||
response_object = requests.patch(self.api_base_url + endpoint, data=params, headers=headers,
|
|
||||||
files=files, timeout=self.request_timeout)
|
|
||||||
|
|
||||||
if method == 'DELETE':
|
|
||||||
response_object = requests.delete(self.api_base_url + endpoint, data=params, headers=headers,
|
|
||||||
files=files, timeout=self.request_timeout)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MastodonNetworkError("Could not complete request: %s" % e)
|
raise MastodonNetworkError("Could not complete request: %s" % e)
|
||||||
|
|
||||||
if response_object is None:
|
|
||||||
raise MastodonIllegalArgumentError("Illegal request.")
|
|
||||||
|
|
||||||
# Handle response
|
# Handle response
|
||||||
if self.debug_requests:
|
if self.debug_requests:
|
||||||
print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')
|
print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')
|
||||||
|
|
Loading…
Referencia en una nova incidència