其他分享
首页 > 其他分享> > 可能导致xmlrpclib.ResponseError:ResponseError()的原因?

可能导致xmlrpclib.ResponseError:ResponseError()的原因?

作者:互联网

我正在尝试XML-RPC.

我有以下服务器脚本(Python):

from SimpleXMLRPCServer import SimpleXMLRPCServer

server = SimpleXMLRPCServer(('localhost', 9000))

def return_input(someinput):
return someinput

server.register_function(return_input)

try:
     print 'ctrl-c to stop server'
     server.serve_forever()
except KeyboardInterrupt:
     print 'stopping'

和以下客户端脚本:

import xmlrpclib

server = xmlrpclib.ServerProxy('http://www.example.com/pathto/xmlrpcTester2.py')
print server.return_input('some input')

我已经在本地测试过,并且效果很好.它所做的一切都会吐出客户端脚本的输入,这是正确的.

但是,当我尝试在远程服务器上执行此操作时,出现以下错误:

Traceback (most recent call last):
  File "client.py", line 4, in <module>
    print server.return_input('some input')
  File     "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line     1199, in __call__
    return self.__send(self.__name, args)
  File     "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line     1489, in __request
    verbose=self.__verbose
  File     "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line     1253, in request
return self._parse_response(h.getfile(), sock)
 File     "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line     1392, in _parse_response
return u.close()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 836, in close
raise ResponseError()
xmlrpclib.ResponseError: ResponseError()

有什么想法会导致这种情况吗?

更新:

当verbose = True时:

send: 'POST /pythonScripts/xmlrpcTester2.py HTTP/1.0\r\nHost:         www.example.com\r\nUser-Agent: xmlrpclib.py/1.0.1 (by www.pythonware.com)\r\nContent-    Type: text/xml\r\nContent-Length: 166\r\n\r\n'
send: "<?xml version='1.0'?    >\n<methodCall>\n<methodName>return_input</methodName>\n<params>\n<param>\n<value><string>so  me input</string></value>\n</param>\n</params>\n</methodCall>\n"
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Fri, 14 May 2010 20:52:25 GMT
header: Server: Apache/2.2.9 (Fedora)
header: Last-Modified: Fri, 14 May 2010 20:52:03 GMT
header: ETag: "7e206-13d-486940c17a2c0"
header: Accept-Ranges: bytes
header: Content-Length: 317
header: Connection: close
header: Content-Type: text/plain; charset=UTF-8
body: "from SimpleXMLRPCServer import SimpleXMLRPCServer\r\n\r\nserver =    SimpleXMLRPCServer(('localhost', 8000))\r\n\r\ndef return_input(someinput):\r\n\treturn     someinput\r\n\r\nserver.register_function(return_input)\r\n\r\ntry:\r\n     print 'ctrl-c to     stop server'\r\n     server.serve_forever()\r\nexcept KeyboardInterrupt:\r\n     print     'stopping'"
Traceback (most recent call last):
  File "client.py", line 4, in <module>
    print server.return_input('some input')
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1392, in _parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 836, in close
    raise ResponseError()
xmlrpclib.ResponseError: ResponseError()

解决方法:

看起来远程计算机上的该端口上正在运行其他内容.并发回意外的答案.

我将检查服务器是否正常启动.然后检查防火墙设置中是否有任何可能影响事物的因素.

您也可以在客户端中打开详细标志,以查看是否有任何问题的答案.

编辑:

因此,详细的输出可以清楚地说明问题:您没有运行服务器,而是通过普通的Web服务器共享了该服务器!

您需要在远程计算机上运行服务器.

标签:xml-rpc,simplexmlrpcserver,python
来源: https://codeday.me/bug/20191210/2098926.html