HTTP客户端
cdumay-rest-client的Python项目详细描述
cdumay rest客户端
此库是一个基本的REST客户机,具有异常格式。在
快速启动
rest,先使用umacdy安装 pip:
$ pip install cdumay-rest-client
接下来,将RESTClient实例添加到代码中:
importjson,sysfromcdumay_rest_client.clientimportRESTClientclient=RESTClient(server="http://jsonplaceholder.typicode.com")json.dump(client.do_request(method="GET",path="/posts/1"),sys.stdout,sort_keys=True,indent=4,separators=(',',': '))
结果:
^{pr2}$异常
您可以使用marshmallow 要序列化异常:
importjson,sysfromcdumay_rest_client.clientimportRESTClientfromcdumay_http_client.exceptionsimportHTTPException,HTTPExceptionValidatortry:client=RESTClient(server="http://jsonplaceholder.typicode.com")data=client.do_request(method="GET",path="/me")exceptHTTPExceptionasexc:data=HTTPExceptionValidator().dump(exc).datajson.dump(data,sys.stdout,sort_keys=True,indent=4,separators=(',',': '))
结果:
{"code":404,"extra":{},"message":"Not Found"}
许可证
根据Apache License 2.0或{a8}授权。在
- 项目
标签: