3

我正在试验 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()
4

1 回答 1

3

看起来其他东西正在远程机器上的那个端口上运行。并发回一个意想不到的答案。

我会检查服务器是否正确启动。然后检查防火墙设置中是否有任何可能影响事物的东西。

您还可以打开客户端中的详细标志以查看是否可以解决问题。

编辑:

因此,详细的输出清楚地表明了问题:您没有运行服务器,而是通过普通的网络服务器共享它!

您需要在远程机器上运行服务器。

于 2010-05-14T20:39:09.377 回答