瓶子的错误测试插件

bottle_errorsrest的Python项目详细描述


瓶子错误测试瓶子的插件

现在,所有错误都将返回bottle json格式。

如果httperror接收到的字符串变为{'message':string}

安装

通过PIP:^{TT1}$

或克隆:git clone https://github.com/agalera/bottle_errorsrest.git

示例服务器:

frombottleimportget,install,run,HTTPErrorfrombottle_errorsrestimportErrorsRestPlugin@get("/")defexample():# {'message': 'oh no!'}raiseHTTPError(500,"oh no!")@get("/2")defexample2():# {'other_Example': 'oh no!'}raiseHTTPError(500,{'other_Example':'oh no!'})install(ErrorsRestPlugin())run(host="0.0.0.0",port="9988")

测试:

curl http://localhost:9988/ --head; curl http://localhost:9988/
HTTP/1.0 500 Internal Server Error
Date: Tue, 27 Sep 201611:16:41 GMT
Server: WSGIServer/0.2 CPython/3.4.3
Content-Type: application/json
Content-Length: 20{"message": "oh no!"}

curl http://localhost:9988/2 --head; curl http://localhost:9988/2
HTTP/1.0 500 Internal Server Error
Date: Tue, 27 Sep 201611:16:41 GMT
Server: WSGIServer/0.2 CPython/3.4.3
Content-Type: application/json
Content-Length: 20{"other_Example": "oh no!"}

curl http://localhost:9988/not_found --head; curl http://localhost:9988/not_found
HTTP/1.0 404 Not Found
Date: Tue, 27 Sep 201611:11:39 GMT
Server: WSGIServer/0.2 CPython/3.4.3
Content-Length: 38
Content-Type: application/json

{"message": "Not found: '/not_found'"}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaJSonarray不会从SeekBar读取double   使用另一个类从Java中的2D数组打印用户输入   java ClassNotFoundException的原因   spring调用两个方法以返回Java中的不同页面   httpurlconnection Java禁止的代码错误,但浏览器错误(2)   java画布矩阵转换   java:在另一个java映射中使用“Map”作为值   java“未找到用于解密的证书”(Apache CXF,WSSecurity)   java如何查看JTable中选择的行   java在没有xmlwrappers的情况下重复xml元素序列集   java将垂直直方图打印到控制台   java Spring JDBCTemplate:构造不带特殊字符的JSON   java PayPal RestApi获取用户信息