From 4377f1c2842f909d05022a211bd67449a54a6db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 13 Nov 2021 22:44:11 +0100 Subject: [PATCH] [twitter] distinguish between fatal & nonfatal errors (#2020) only show a warning for nonfatal errors and do not raise a StopExtraction exception --- gallery_dl/extractor/twitter.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index 00f3b041..b1636385 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -793,16 +793,21 @@ class TwitterAPI(): data = response.json() if "errors" in data: try: - msg = ", ".join( - '"' + error["message"] + '"' - for error in data["errors"] - ) + errors, warnings = [], [] + for error in data["errors"]: + if error.get("kind") == "NonFatal": + warnings.append(error["message"]) + else: + errors.append(error["message"]) + errors = ", ".join(errors) except Exception: - msg = data["errors"] - if msg and response.status_code < 400: - raise exception.StopExtraction(msg) + errors = data["errors"] + if warnings: + self.extractor.log.warning(", ".join(warnings)) + if errors and response.status_code < 400: + raise exception.StopExtraction(errors) else: - msg = "" + errors = "" if response.status_code < 400: # success @@ -816,7 +821,7 @@ class TwitterAPI(): continue if response.status_code == 401 and \ - "have been blocked from viewing" in msg: + "have been blocked from viewing" in errors: # account blocked extr = self.extractor if self.headers["x-twitter-auth-type"] and \ @@ -833,7 +838,7 @@ class TwitterAPI(): # error raise exception.StopExtraction( - "%s %s (%s)", response.status_code, response.reason, msg) + "%s %s (%s)", response.status_code, response.reason, errors) def _pagination(self, endpoint, params=None): if params is None: