Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
5f06cf9c
Commit
5f06cf9c
authored
May 28, 2015
by
Joshua Roesslein
Browse files
Merge pull request #611 from obskyr/master
Added RateLimitError for easily working with the rate limit.
parents
0279a4e9
c2e32f86
Changes
4
Hide whitespace changes
Inline
Side-by-side
CONTRIBUTORS
View file @
5f06cf9c
...
...
@@ -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)
tweepy/__init__.py
View file @
5f06cf9c
...
...
@@ -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
...
...
tweepy/binder.py
View file @
5f06cf9c
...
...
@@ -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
)
...
...
tweepy/error.py
View file @
5f06cf9c
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment