From 5e15e2a2f568395cb77035782a1a4c5d03a3b3a2 Mon Sep 17 00:00:00 2001 From: Harmon Date: Wed, 29 Sep 2021 00:26:43 -0500 Subject: [PATCH] Improve Client.request formatting --- tweepy/client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tweepy/client.py b/tweepy/client.py index 1077e17..59123b4 100644 --- a/tweepy/client.py +++ b/tweepy/client.py @@ -92,12 +92,14 @@ class Client: auth = auth.apply_auth() else: headers["Authorization"] = f"Bearer {self.bearer_token}" + log.debug( f"Making API request: {method} {host + route}\n" f"Parameters: {params}\n" f"Headers: {headers}\n" f"Body: {json}" ) + with self.session.request( method, host + route, params=params, json=json, headers=headers, auth=auth @@ -108,6 +110,7 @@ class Client: f"Headers: {response.headers}\n" f"Content: {response.content}" ) + if response.status_code == 400: raise BadRequest(response) if response.status_code == 401: @@ -132,6 +135,7 @@ class Client: raise TwitterServerError(response) if not 200 <= response.status_code < 300: raise HTTPException(response) + return response def _make_request(self, method, route, params={}, endpoint_parameters=None, -- 2.25.1