From 5bc1706aa214dde0a04afdad364e1e8d08a54518 Mon Sep 17 00:00:00 2001 From: codl Date: Wed, 4 Oct 2017 16:17:03 +0200 Subject: [PATCH] clean up methods handling, let Requests worry about methods --- mastodon/Mastodon.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 5b198a5..bbdf12f 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1024,29 +1024,14 @@ class Mastodon: while not request_complete: request_complete = True - response_object = None try: - if method == 'GET': - response_object = requests.get(self.api_base_url + endpoint, params=params, - headers=headers, files=files, - 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) + response_object = requests.request( + method, self.api_base_url + endpoint, params=params, + headers=headers, files=files, + timeout=self.request_timeout) except Exception as e: raise MastodonNetworkError("Could not complete request: %s" % e) - if response_object is None: - raise MastodonIllegalArgumentError("Illegal request.") - # Handle response if self.debug_requests: print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')