From: Harmon Date: Sun, 4 Apr 2021 13:52:42 +0000 (-0500) Subject: Add NotFound X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2d84b270408944e784b32199faa09fb553f6250d;p=tweepy.git Add NotFound --- diff --git a/tweepy/__init__.py b/tweepy/__init__.py index 4eb0ad3..0abf182 100644 --- a/tweepy/__init__.py +++ b/tweepy/__init__.py @@ -13,7 +13,7 @@ from tweepy.api import API from tweepy.auth import AppAuthHandler, OAuthHandler from tweepy.cache import Cache, FileCache, MemoryCache from tweepy.cursor import Cursor -from tweepy.errors import HTTPException, TooManyRequests, TweepyException +from tweepy.errors import HTTPException, NotFound, TooManyRequests, TweepyException from tweepy.models import DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults, Status, User from tweepy.streaming import Stream diff --git a/tweepy/api.py b/tweepy/api.py index f6f3186..19715fb 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -12,7 +12,7 @@ from urllib.parse import urlencode import requests -from tweepy.errors import HTTPException, TooManyRequests, TweepyException +from tweepy.errors import HTTPException, NotFound, TooManyRequests, TweepyException from tweepy.models import Model from tweepy.parsers import ModelParser, Parser from tweepy.utils import list_to_csv @@ -208,6 +208,8 @@ class API: # If an error was returned, throw an exception self.last_response = resp + if resp.status_code == 404: + raise NotFound(resp) if resp.status_code == 429: raise TooManyRequests(resp) if resp.status_code and not 200 <= resp.status_code < 300: diff --git a/tweepy/errors.py b/tweepy/errors.py index e157147..93c4777 100644 --- a/tweepy/errors.py +++ b/tweepy/errors.py @@ -43,6 +43,11 @@ class HTTPException(TweepyException): ) +class NotFound(HTTPException): + """Exception raised for a 404 HTTP status code""" + pass + + class TooManyRequests(HTTPException): """Exception raised for a 429 HTTP status code""" pass