Commit 5f06cf9c authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

Merge pull request #611 from obskyr/master

Added RateLimitError for easily working with the rate limit.
parents 0279a4e9 c2e32f86
......@@ -33,4 +33,5 @@ Jeff Hull (@jsh2134)
Mike (mikeandmore)
Kohei YOSHIDA
Mark Smith (@judy2k)
Steven Skoczen (@skoczen)
\ No newline at end of file
Steven Skoczen (@skoczen)
Samuel (@obskyr)
......@@ -10,7 +10,7 @@ __author__ = 'Joshua Roesslein'
__license__ = 'MIT'
from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResults, ModelFactory, Category
from tweepy.error import TweepError
from tweepy.error import TweepError, RateLimitError
from tweepy.api import API
from tweepy.cache import Cache, MemoryCache, FileCache
from tweepy.auth import OAuthHandler, AppAuthHandler
......
......@@ -12,7 +12,7 @@ import requests
import logging
from tweepy.error import TweepError
from tweepy.error import TweepError, RateLimitError, is_rate_limit_error_message
from tweepy.utils import convert_to_utf8_str
from tweepy.models import Model
......@@ -220,7 +220,11 @@ def bind_api(**config):
error_msg = self.parser.parse_error(resp.text)
except Exception:
error_msg = "Twitter error response: status code = %s" % resp.status_code
raise TweepError(error_msg, resp)
if is_rate_limit_error_message(error_msg):
raise RateLimitError(error_msg, resp)
else:
raise TweepError(error_msg, resp)
# Parse the response payload
result = self.parser.parse(self, resp.text)
......
......@@ -6,7 +6,6 @@ from __future__ import print_function
import six
class TweepError(Exception):
"""Tweepy exception"""
......@@ -17,3 +16,16 @@ class TweepError(Exception):
def __str__(self):
return self.reason
def is_rate_limit_error_message(message):
"""Check if the supplied error message belongs to a rate limit error."""
return isinstance(message, list) \
and len(message) > 0 \
and 'code' in message[0] \
and message[0]['code'] == 88
class RateLimitError(TweepError):
"""Exception for Tweepy hitting the rate limit."""
# RateLimitError has the exact same properties and inner workings
# as TweepError for backwards compatibility reasons.
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment