Requirement and documentation fixes
This commit is contained in:
pare
3ce225dbef
commit
69f78773a0
S'han modificat 3 arxius amb 19 adicions i 15 eliminacions
|
@ -41,9 +41,10 @@ node running Mastodon.
|
|||
|
||||
A note about rate limits
|
||||
------------------------
|
||||
Mastodons API rate limits per IP. Mastodon.py has three modes for dealing
|
||||
with rate limiting that you can pass to the constructor, "throw", "wait"
|
||||
and "pace", "wait" being the default.
|
||||
Mastodons API rate limits per IP. By default, the limit is 150 requests per 5 minute
|
||||
time slow. This can differ from instance to instance and is subject to change.
|
||||
Mastodon.py has three modes for dealing with rate limiting that you can pass to
|
||||
the constructor, "throw", "wait" and "pace", "wait" being the default.
|
||||
|
||||
In "throw" mode, Mastodon.py makes no attempt to stick to rate limits. When
|
||||
a request hits the rate limit, it simply throws a MastodonRateLimitError. This is
|
||||
|
|
|
@ -97,6 +97,9 @@ class Mastodon:
|
|||
self.ratelimit_lastcall = time.time()
|
||||
self.ratelimit_pacefactor = ratelimit_pacefactor
|
||||
|
||||
if not ratelimit_method in ["throw", "wait", "pace"]:
|
||||
raise MastodonIllegalArgumentError("Invalid ratelimit method.")
|
||||
|
||||
if os.path.isfile(self.client_id):
|
||||
with open(self.client_id, 'r') as secret_file:
|
||||
self.client_id = secret_file.readline().rstrip()
|
||||
|
@ -521,11 +524,11 @@ class Mastodon:
|
|||
raise MastodonAPIError("Could not parse response as JSON, respose code was " + str(response_object.status_code))
|
||||
|
||||
# Handle rate limiting
|
||||
try:
|
||||
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
||||
self.ratelimit_remaining = int(response_object.headers['X-RateLimit-Remaining'])
|
||||
self.ratelimit_limit = int(response_object.headers['X-RateLimit-Limit'])
|
||||
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
||||
self.ratelimit_remaining = int(response_object.headers['X-RateLimit-Remaining'])
|
||||
self.ratelimit_limit = int(response_object.headers['X-RateLimit-Limit'])
|
||||
|
||||
try:
|
||||
ratelimit_reset_datetime = dateutil.parser.parse(response_object.headers['X-RateLimit-Reset'])
|
||||
self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime)
|
||||
|
||||
|
@ -535,10 +538,12 @@ class Mastodon:
|
|||
server_time_diff = time.time() - server_time
|
||||
self.ratelimit_reset += server_time_diff
|
||||
self.ratelimit_lastcall = time.time()
|
||||
|
||||
if "error" in response and response["error"] == "Throttled":
|
||||
if self.ratelimit_method == "throw":
|
||||
raise MastodonRatelimitError("Hit rate limit.")
|
||||
except:
|
||||
raise MastodonRatelimitError("Rate limit time calculations failed.")
|
||||
|
||||
if "error" in response and response["error"] == "Throttled":
|
||||
if self.ratelimit_method == "throw":
|
||||
raise MastodonRatelimitError("Hit rate limit.")
|
||||
|
||||
if self.ratelimit_method == "wait" or self.ratelimit_method == "pace":
|
||||
to_next = self.ratelimit_reset - time.time()
|
||||
|
@ -546,9 +551,7 @@ class Mastodon:
|
|||
# As a precaution, never sleep longer than 5 minutes
|
||||
to_next = min(to_next, 5 * 60)
|
||||
time.sleep(to_next)
|
||||
request_complete = False
|
||||
except:
|
||||
raise MastodonRatelimitError("Rate limit time calculations failed.")
|
||||
request_complete = False
|
||||
|
||||
return response
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ setup(name='Mastodon.py',
|
|||
version='1.0.1',
|
||||
description='Python wrapper for the Mastodon API',
|
||||
packages=['mastodon'],
|
||||
install_requires=['requests'],
|
||||
install_requires=['requests', 'dateutil'],
|
||||
url='https://github.com/halcy/Mastodon.py',
|
||||
author='Lorenz Diener',
|
||||
author_email='lorenzd+mastodonpypypi@gmail.com',
|
||||
|
|
Loading…
Referencia en una nova incidència