Properly handle HTTP request errors with no Twitter API errors
authorHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 16:03:49 +0000 (11:03 -0500)
committerHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 16:03:49 +0000 (11:03 -0500)
tweepy/errors.py

index 1ddaff60fe941398c5aea11a01b0b5ddd135d977..d7b0767de75a0ed69c9ec7a511c240a8f7fe79ed 100644 (file)
@@ -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: