瓶子的错误测试插件

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第三方库


热门话题
Spring3MVC:将JavaMIMessage电子邮件显示为html   java从嵌套列表中获取最大值,并使用流将其转换为一个列表   内存泄漏java StackOverflower在无限循环中抛出错误   java线性回归,标准误差问题   java如何使用HQL/Hibernate验证我的所有表都是空的?   java扫描封闭空间   Java和Selenium:在id和选择器写得不好时获取列表内容   java数组项的索引不断增加这很简单,我不知道怎么做   java重用来自不同类的变量?   java为什么我的递归函数在循环中失败?   如何在Java单例枚举构造函数中调用方法?   HDFS上的java文件,用于初始化Flink作业中的对象   io Java:如何处理试图修改同一文件的两个进程   java从MySql迁移:MariaDB服务器意外关闭客户端连接   这是我写的代码,但是提交不起作用。其显示RE(NZEC)错误   java垃圾收集的“隔离岛”   java调用另一个类中的AppCompatActivity类   java spring@Value注释、继承和公共字段,但值不同   java重载未按预期运行