[英]How to specify the xmlrpc faultcode in the server code for python
The xmlrpclib of python is a convenient way to communicate to a different computer over the internet, providing direct access to classes, functions and more. python的xmlrpclib是通过Internet与另一台计算机通信的便捷方法,可直接访问类,函数等。 In the case of an error on the server side, this error is reported to the client side as a fault , consisting of some text-message and some fault-code.
如果服务器端发生错误,此错误将作为故障报告给客户端,该故障由一些文本消息和一些故障代码组成。
The question I have, is how one can control these attributes on the server side, ie how to explicitly set the faultString and the faultCode to be sent to the client. 我的问题是,如何在服务器端控制这些属性,即如何显式设置faultString和faultCode以发送给客户端。 The documentation seems very sparse in these details, and any help is appreciated.
这些细节中的文档似乎非常稀疏,不胜感激。
Thanks, 谢谢,
Alex 亚历克斯
After some digging I found an answer. 经过一番挖掘,我找到了答案。 To 'throw' an fault in the xmlrpc server, one can do simply
要“抛出” xmlrpc服务器中的故障,可以简单地做
import xmlrpclib
# some code
if not ok:
# throw fault:
raise xmlrpclib.Fault(11, "some message")
which raises a Fault with faultCode 11 and faultString "some messsage" on the client side. 这会在客户端上引发带有FaultCode 11和faultString“ some message”的Fault。 This can be overridden to implement own error classes.
可以重写此方法以实现自己的错误类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.