Skip to content

Commit

Permalink
Add Unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Apr 4, 2021
1 parent 2d84b27 commit 3ffec76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions tweepy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
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
Expand Down
6 changes: 5 additions & 1 deletion tweepy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

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
Expand Down Expand Up @@ -208,6 +210,8 @@ def request(

# 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:
Expand Down
5 changes: 5 additions & 0 deletions tweepy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def __init__(self, response):
)


class Unauthorized(HTTPException):
"""Exception raised for a 401 HTTP status code"""
pass


class NotFound(HTTPException):
"""Exception raised for a 404 HTTP status code"""
pass
Expand Down

0 comments on commit 3ffec76

Please sign in to comment.