尝试使用该代码从“before_request”处理程序(在Flask中)中止时会出现以下错误:LookupError: no exception for 429
。有办法解决这个问题吗?
以下是触发错误的代码:
key = "ip:{}:account-requests".format(request.remote_addr)
# Determine how many requests have been made in the past day
# by this API.
requests_made = r.get(key) or 0
if requests_made >= max_requests:
abort(429) #HTTP Too Many Requests
答案 0 :(得分:4)
你可以在Flask
中这样做if requests_made >= max_requests:
return '429 error', 429