瓶子的错误测试插件
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'"}