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
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
# 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:
)
+class Unauthorized(HTTPException):
+ """Exception raised for a 401 HTTP status code"""
+ pass
+
+
class NotFound(HTTPException):
"""Exception raised for a 404 HTTP status code"""
pass