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
3e752d71
Commit
3e752d71
authored
May 18, 2015
by
obskyr
Browse files
Added RateLimitError. Resolves #600.
Can't believe this hasn't been in until now! Huh.
parent
2f3c61ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
tweepy/__init__.py
View file @
3e752d71
...
...
@@ -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 @
3e752d71
...
...
@@ -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 @
3e752d71
...
...
@@ -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