From: Harmon Date: Thu, 21 Apr 2022 23:22:28 +0000 (-0500) Subject: Handle "error" key of response being a string in HTTPException X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2da4452870093f930fb8808861bcec809a2d4ccf;p=tweepy.git Handle "error" key of response being a string in HTTPException --- diff --git a/tweepy/errors.py b/tweepy/errors.py index 309c6be..cea3efe 100644 --- a/tweepy/errors.py +++ b/tweepy/errors.py @@ -45,16 +45,26 @@ class HTTPException(TweepyException): super().__init__(f"{response.status_code} {response.reason}") else: errors = response_json.get("errors", []) + # Use := when support for Python 3.7 is dropped if "error" in response_json: errors.append(response_json["error"]) + error_text = "" + for error in errors: self.api_errors.append(error) + + if isinstance(error, str): + self.api_messages.append(error) + error_text += '\n' + error + continue + if "code" in error: self.api_codes.append(error["code"]) if "message" in error: self.api_messages.append(error["message"]) + if "code" in error and "message" in error: error_text += f"\n{error['code']} - {error['message']}" elif "message" in error: