From f4c51d42989b9cd0c2b1a003c3f2b4c6dc2aa20a Mon Sep 17 00:00:00 2001 From: RGBCube <78925721+RGBCube@users.noreply.github.com> Date: Mon, 27 Jun 2022 13:55:44 +0300 Subject: [PATCH] Make HTTPClient.request work with clean text responses too --- github/internals/http.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/github/internals/http.py b/github/internals/http.py index dc7e84a..938cf59 100644 --- a/github/internals/http.py +++ b/github/internals/http.py @@ -172,9 +172,9 @@ class HTTPClient: async with self.__session.request( method, f"https://api.github.com{path}", **kwargs - ) as request: + ) as response: - headers = request.headers + headers = response.headers self._rates = RateLimits( int(headers["X-RateLimit-Remaining"]), @@ -186,10 +186,13 @@ class HTTPClient: datetime.now(timezone.utc), ) - if 200 <= request.status <= 299: - return await request.json() + if 200 <= response.status <= 299: + if response.headers["Content-Type"] == "application/json": + return await response.json() - raise error_from_request(request) + return await response.text(encoding="utf-8") + + raise error_from_request(response) # === ROUTES === #