python-3.x - 如何更改烧瓶限制器错误页面?
问题描述
我在某些地方使用烧瓶限制器库以避免过度拥挤。当请求太多时,我在下面抛出的页面会转动。我想更改此页面。返回此页面的代码如下。
"""
errors and exceptions
"""
from distutils.version import LooseVersion
from pkg_resources import get_distribution
from six import text_type
from werkzeug import exceptions
werkzeug_exception = None
werkzeug_version = get_distribution("werkzeug").version
if LooseVersion(werkzeug_version) < LooseVersion("0.9"): # pragma: no cover
# sorry, for touching your internals :).
import werkzeug._internal
werkzeug._internal.HTTP_STATUS_CODES[429] = 'Too Many Requests'
werkzeug_exception = exceptions.HTTPException
else:
# Werkzeug 0.9 and up have an existing exception for 429
werkzeug_exception = exceptions.TooManyRequests
class RateLimitExceeded(werkzeug_exception):
"""
exception raised when a rate limit is hit.
The exception results in ``abort(429)`` being called.
"""
code = 429
limit = None
def __init__(self, limit):
self.limit = limit
if limit.error_message:
description = limit.error_message if not callable(
limit.error_message
) else limit.error_message()
else:
description = text_type(limit.limit)
super(RateLimitExceeded, self).__init__(description=description)
解决方案
推荐阅读
- c# - 获取当前登录用户的名字
- distributed-system - etcd 如何将写入传播给非领导成员?
- android - 如何正确解析 Firestore API JSON?
- c# - c#如何在后台为数组创建Array抽象类的实例?
- python - 如何修复:KeyError: '__file__' in sitecustomize.py (anaconda3) when using run file (F5)
- angular - 在ngrx中有很多动作是正常的吗?
- reactjs - 如何在 React 中检索存储在 Firebase 存储中的 txt 文件中的数据?
- c - scanf 和 getchar 一起读取字符串
- spring-mvc - 如何将 MultipartFile( image ) 转换为 DataSource 对象
- c# - 在来自不同类的图像上绘制矩形