1

尝试使用该代码从“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
4

1 回答 1

4

你可以在 Flask 中这样做

if requests_made >= max_requests:
    return '429 error', 429
于 2012-07-01T00:51:35.080 回答