Add Unauthorized
authorHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 13:57:11 +0000 (08:57 -0500)
committerHarmon <Harmon758@gmail.com>
Sun, 4 Apr 2021 13:59:01 +0000 (08:59 -0500)
tweepy/__init__.py
tweepy/api.py
tweepy/errors.py

index 0abf18207c9d435751c99287b5e55fffb0c366e6..64c0dcf15d23d3d61513406be899b1023472e731 100644 (file)
@@ -13,8 +13,13 @@ 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, NotFound, TooManyRequests, TweepyException
-from tweepy.models import DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults, Status, User
+from tweepy.errors import (
+    HTTPException, NotFound, TooManyRequests, TweepyException, Unauthorized
+)
+from tweepy.models import (
+    DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults,
+    Status, User
+)
 from tweepy.streaming import Stream
 
 # Global, unauthenticated instance of API
index 19715fb199b1232a40e5e2a6d8839909c10d91cc..acaef20ac7ff616d5350764775aa7ad5ae9ea470 100644 (file)
@@ -12,7 +12,9 @@ from urllib.parse import urlencode
 
 import requests
 
-from tweepy.errors import HTTPException, NotFound, TooManyRequests, TweepyException
+from tweepy.errors import (
+    HTTPException, NotFound, TooManyRequests, TweepyException, Unauthorized
+)
 from tweepy.models import Model
 from tweepy.parsers import ModelParser, Parser
 from tweepy.utils import list_to_csv
@@ -208,6 +210,8 @@ class API:
 
             # If an error was returned, throw an exception
             self.last_response = resp
+            if resp.status_code == 401:
+                raise Unauthorized(resp)
             if resp.status_code == 404:
                 raise NotFound(resp)
             if resp.status_code == 429:
index 93c4777efb7c42e1b81a44b407da5d53c21392a5..f27a6377cf399b502ecbded2b21cb3f6a365b4a3 100644 (file)
@@ -43,6 +43,11 @@ class HTTPException(TweepyException):
             )
 
 
+class Unauthorized(HTTPException):
+    """Exception raised for a 401 HTTP status code"""
+    pass
+
+
 class NotFound(HTTPException):
     """Exception raised for a 404 HTTP status code"""
     pass