From 4a9bc58f1006c1b2b1310d4a6cd821e23d9c8c79 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sun, 4 Apr 2021 09:06:12 -0500 Subject: [PATCH] Add Forbidden --- tweepy/__init__.py | 3 ++- tweepy/api.py | 5 ++++- tweepy/errors.py | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tweepy/__init__.py b/tweepy/__init__.py index 64c0dcf..f08249f 100644 --- a/tweepy/__init__.py +++ b/tweepy/__init__.py @@ -14,7 +14,8 @@ from tweepy.auth import AppAuthHandler, OAuthHandler from tweepy.cache import Cache, FileCache, MemoryCache from tweepy.cursor import Cursor from tweepy.errors import ( - HTTPException, NotFound, TooManyRequests, TweepyException, Unauthorized + Forbidden, HTTPException, NotFound, TooManyRequests, TweepyException, + Unauthorized ) from tweepy.models import ( DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults, diff --git a/tweepy/api.py b/tweepy/api.py index acaef20..7557991 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -13,7 +13,8 @@ from urllib.parse import urlencode import requests from tweepy.errors import ( - HTTPException, NotFound, TooManyRequests, TweepyException, Unauthorized + Forbidden, HTTPException, NotFound, TooManyRequests, TweepyException, + Unauthorized ) from tweepy.models import Model from tweepy.parsers import ModelParser, Parser @@ -212,6 +213,8 @@ class API: self.last_response = resp if resp.status_code == 401: raise Unauthorized(resp) + if resp.status_code == 403: + raise Forbidden(resp) if resp.status_code == 404: raise NotFound(resp) if resp.status_code == 429: diff --git a/tweepy/errors.py b/tweepy/errors.py index f27a637..e241796 100644 --- a/tweepy/errors.py +++ b/tweepy/errors.py @@ -48,6 +48,11 @@ class Unauthorized(HTTPException): pass +class Forbidden(HTTPException): + """Exception raised for a 403 HTTP status code""" + pass + + class NotFound(HTTPException): """Exception raised for a 404 HTTP status code""" pass -- 2.25.1