From 5faafa111f002d065ba05c35974c21dd99cb43af Mon Sep 17 00:00:00 2001 From: Harmon Date: Sun, 4 Apr 2021 11:03:49 -0500 Subject: [PATCH] Properly handle HTTP request errors with no Twitter API errors --- tweepy/errors.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tweepy/errors.py b/tweepy/errors.py index 1ddaff6..d7b0767 100644 --- a/tweepy/errors.py +++ b/tweepy/errors.py @@ -26,9 +26,12 @@ class HTTPException(TweepyException): super().__init__(f"{response.status_code} {response.reason}") else: error_text = [] - for error in response_json.get("errors"): + # Use := when support for Python 3.7 is dropped + if "errors" not in response_json: + super().__init__(f"{response.status_code} {response.reason}") + return + for error in response_json["errors"]: self.api_errors.append(error) - # Use := when support for Python 3.7 is dropped if "code" in error: self.api_codes.append(error["code"]) if "message" in error: -- 2.25.1