具有更好错误报告功能的 XML-RPC 服务器
标准库(Python 2 中的 xmlrpclib
+SimpleXMLRPCServer
和 Python 3 中的 xmlrpc.server
)将所有错误(包括使用错误)报告为 python 异常,其中不适合公共服务:如果没有Python知识,异常字符串通常不容易理解,并且可能会暴露一些敏感信息。解决这个问题并不难,但我更愿意避免重新发明轮子。有没有更好的错误报告的第三方库?我对所有使用错误的良好故障消息以及报告内部错误时隐藏内部结构感兴趣(最好通过日志记录来完成)。
xmlrpclib
已具有此类错误的常量:NOT_WELLFORMED_ERROR
、UNSUPPORTED_ENCODING
、INVALID_ENCODING_CHAR
、INVALID_XMLRPC
>、METHOD_NOT_FOUND
、INVALID_METHOD_PARAMS
、INTERNAL_ERROR
。
Standard libraries (xmlrpclib
+SimpleXMLRPCServer
in Python 2 and xmlrpc.server
in Python 3) report all errors (including usage errors) as python exceptions which is not suitable for public services: exception strings are often not easy understandable without python knowledge and might expose some sensitive information. It's not hard to fix this, but I prefer to avoid reinventing the wheel. Is there a third party library with better error reporting? I'm interested in good fault messages for all usage errors and hiding internals when reporting internal errors (this is better done with logging).
xmlrpclib
already have the constants for such errors: NOT_WELLFORMED_ERROR
, UNSUPPORTED_ENCODING
, INVALID_ENCODING_CHAR
, INVALID_XMLRPC
, METHOD_NOT_FOUND
, INVALID_METHOD_PARAMS
, INTERNAL_ERROR
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你有图书馆特定的问题。使用任何库或框架时,您通常希望捕获所有错误,将它们记录在某处,然后抛出“哎呀,我们遇到了问题。您可能需要通过 [电子邮件受保护],错误号为 100,并告诉我们您做了什么。"因此,将您的失败入口点包装在 try/catch 中,创建一个通用记录器,然后就可以了...
I don't think you have a library specific problem. When using any library or framework you typically want to trap all errors, log them somewhere, and throw up "Oops, we're having problems. You may want to contact us at [email protected] with error number 100 and tell us what you did." So wrap your failable entry points in try/catches, create a generic logger and off you go...
看起来没有现成的库可以满足我的要求,所以最终有了自己的实现:
It look like there is no ready library with my requirements, so a ended up with own implementation: