Skip to content

Instantly share code, notes, and snippets.

@seozed
Created June 8, 2020 08:06
Show Gist options
  • Save seozed/097dd9f7f25924645ae8be60f5e2cec2 to your computer and use it in GitHub Desktop.
Save seozed/097dd9f7f25924645ae8be60f5e2cec2 to your computer and use it in GitHub Desktop.
[限制客户端请求速度的装饰器] #qps
from ratelimit import limits, sleep_and_retry
import requests
FIFTEEN_MINUTES = 900
@sleep_and_retry
@limits(calls=15, period=FIFTEEN_MINUTES)
# 900秒内最多请求15次。
def call_api(url):
response = requests.get(url)
if response.status_code != 200:
raise Exception('API response: {}'.format(response.status_code))
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment