如何在 xmlrpc 服务器而不是客户端上查看回溯?

发布于 2024-10-11 03:59:32 字数 1462 浏览 2 评论 0原文

我有简单的 xmlrpc 服务器代码:

from SimpleXMLRPCServer import SimpleXMLRPCServer

port = 9999

def func():
    print 'Hi!'
    print x # error!
    print 'Bye!'

if __name__ == '__main__':
    server = SimpleXMLRPCServer(("localhost", port))
    print "Listening on port %s..." % port
    server.register_function(func)
    server.serve_forever()

示例会话。

客户端:

>>> import xmlrpclib
>>> p = xmlrpclib.ServerProxy('http://localhost:9999')
>>> p.func()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "C:\Python26\lib\xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "C:\Python26\lib\xmlrpclib.py", line 1392, in _parse_response
    return u.close()
  File "C:\Python26\lib\xmlrpclib.py", line 838, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<type 'exceptions.NameError'>:global name 'x' is not defined">
>>>

服务器:

Listening on port 9999...
Hi!
localhost - - [11/Jan/2011 16:17:09] "POST /RPC2 HTTP/1.0" 200 -

问题是我是否也可以在服务器上获取此跟踪。我需要知道处理查询时是否出了问题。我没有使用用 Python 编写的客户端,所以我很难像上面那样获得回溯。

I have simple xmlrpc server code:

from SimpleXMLRPCServer import SimpleXMLRPCServer

port = 9999

def func():
    print 'Hi!'
    print x # error!
    print 'Bye!'

if __name__ == '__main__':
    server = SimpleXMLRPCServer(("localhost", port))
    print "Listening on port %s..." % port
    server.register_function(func)
    server.serve_forever()

Sample session.

Client:

>>> import xmlrpclib
>>> p = xmlrpclib.ServerProxy('http://localhost:9999')
>>> p.func()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "C:\Python26\lib\xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "C:\Python26\lib\xmlrpclib.py", line 1392, in _parse_response
    return u.close()
  File "C:\Python26\lib\xmlrpclib.py", line 838, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<type 'exceptions.NameError'>:global name 'x' is not defined">
>>>

Server:

Listening on port 9999...
Hi!
localhost - - [11/Jan/2011 16:17:09] "POST /RPC2 HTTP/1.0" 200 -

The question is if I can get this trace back also on server. I need to know if something went wrong with processing query. I'm not using client written in Python so it is hard for me to get traceback like above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娜些时光,永不杰束 2024-10-18 03:59:32

您可以执行以下操作:

from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler

port = 9999

def func():
    print 'Hi!'
    print x # error!
    print 'Bye!'

class Handler(SimpleXMLRPCRequestHandler):
     def _dispatch(self, method, params):
         try: 
             return self.server.funcs[method](*params)
         except:
             import traceback
             traceback.print_exc()
             raise


if __name__ == '__main__':
    server = SimpleXMLRPCServer(("localhost", port), Handler)
    server.register_function(func)
    print "Listening on port %s..." % port
    server.serve_forever()

Traceback 服务器端:

Listening on port 9999...
Hi!
Traceback (most recent call last):
  File "xml.py", line 13, in _dispatch
    value = self.server.funcs[method](*params)
  File "xml.py", line 7, in func
    print x # error!
NameError: global name 'x' is not defined
localhost - - [11/Jan/2011 17:13:16] "POST /RPC2 HTTP/1.0" 200 

You can do something like this:

from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler

port = 9999

def func():
    print 'Hi!'
    print x # error!
    print 'Bye!'

class Handler(SimpleXMLRPCRequestHandler):
     def _dispatch(self, method, params):
         try: 
             return self.server.funcs[method](*params)
         except:
             import traceback
             traceback.print_exc()
             raise


if __name__ == '__main__':
    server = SimpleXMLRPCServer(("localhost", port), Handler)
    server.register_function(func)
    print "Listening on port %s..." % port
    server.serve_forever()

Traceback server side:

Listening on port 9999...
Hi!
Traceback (most recent call last):
  File "xml.py", line 13, in _dispatch
    value = self.server.funcs[method](*params)
  File "xml.py", line 7, in func
    print x # error!
NameError: global name 'x' is not defined
localhost - - [11/Jan/2011 17:13:16] "POST /RPC2 HTTP/1.0" 200 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文