Handle Twitter API errors with successful HTTP status codes
authorHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 15:07:55 +0000 (10:07 -0500)
committerHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 15:07:55 +0000 (10:07 -0500)
tweepy/parsers.py

index a0ca907383ee3e999997cacb28553da0e93f6245..916866c0a2a17e51ae829506401460e20275ac1d 100644 (file)
@@ -73,10 +73,15 @@ class ModelParser(JSONParser):
         else:
             cursors = None
 
-        if payload_list:
-            result = model.parse_list(api, json)
-        else:
-            result = model.parse(api, json)
+        try:
+            if payload_list:
+                result = model.parse_list(api, json)
+            else:
+                result = model.parse(api, json)
+        except KeyError:
+            raise TweepyException(
+                f"Unable to parse response payload: {json}"
+            ) from None
 
         if cursors:
             return result, cursors