2013-03-17 31 views
0

我的配置文件:噓client.py不工作,顯示連接錯誤

Host server 
User new_user 
HostName 10.0.1.193 
Port 55555 
LocalForward 3000 10.0.1.193:6000 
IdentityFile ~/.ssh/server 

Client.py

import xmlrpclib 
s = xmlrpclib.ServerProxy('http://localhost:3000') 
print s.pow(2,3) # Returns 2**3 = 8 
print s.add(2,3) # Returns 5 
print s.div(5,2) # Returns 5//2 = 2 

# Print list of available methods 
print s.system.listMethods() 

Server.py

from SimpleXMLRPCServer import SimpleXMLRPCServer 
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler 

# Restrict to a particular path. 
class RequestHandler(SimpleXMLRPCRequestHandler): 
    rpc_paths = ('/RPC2',) 

# Create server 
server = SimpleXMLRPCServer(("localhost", 6000), 
          requestHandler=RequestHandler) 
server.register_introspection_functions() 

# Register pow() function; this will use the value of 
# pow.__name__ as the name, which is just 'pow'. 
server.register_function(pow) 

# Register a function under a different name 
def adder_function(x,y): 
    return x + y 
server.register_function(adder_function, 'add') 

# Register an instance; all the methods of the instance are 
# published as XML-RPC methods (in this case, just 'div'). 
class MyFuncs: 
    def div(self, x, y): 
     return x // y 

server.register_instance(MyFuncs()) 

# Run the server's main loop 
server.serve_forever() 

我server.py運行很好,但是當我跑我client.py,它提供了以下錯誤:

Traceback (most recent call last): 
    File "client.py", line 4, in <module> 
    print s.pow(2,3) # Returns 2**3 = 8 
    File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__ 
    return self.__send(self.__name, args) 
    File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request 
    verbose=self.__verbose 
    File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request 
    return self.single_request(host, handler, request_body, verbose) 
    File "/usr/lib/python2.7/xmlrpclib.py", line 1292, in single_request 
    self.send_content(h, request_body) 
    File "/usr/lib/python2.7/xmlrpclib.py", line 1439, in send_content 
    connection.endheaders(request_body) 
    File "/usr/lib/python2.7/httplib.py", line 954, in endheaders 
    self._send_output(message_body) 
    File "/usr/lib/python2.7/httplib.py", line 814, in _send_output 
    self.send(msg) 
    File "/usr/lib/python2.7/httplib.py", line 776, in send 
    self.connect() 
    File "/usr/lib/python2.7/httplib.py", line 757, in connect 
    self.timeout, self.source_address) 
    File "/usr/lib/python2.7/socket.py", line 571, in create_connection 
    raise err 
socket.error: [Errno 111] Connection refused 

我已籤,如果我的工作ssh和我可以ssh到遠程服務器與給定的配置,即

ssh server 

作品找到。任何人都可以解釋什麼可能會出錯嗎?

+0

運行client.py之前ssh連接是否打開? – dave4420 2013-03-17 20:12:46

回答

0

你的服務器運行,也許它沒有抱怨,但這並不意味着它「運行正常」或更尖銳,這並不意味着該服務器在客戶端希望工作狀態。

由於某種原因,上述內容有點神祕:未知的東西出了問題,即使您還不知道什麼是壞的,您想開始測試您知道應該工作的東西,並驗證它們實際上正在工作。即使錯誤對您沒有意義,這仍然是一種有用的調試技巧。

在這種情況下,客戶端錯誤信息爲「連接被拒絕」,意思是「拒絕[在服務器]」。在終端/ DOS窗口中的「客戶」的PC上 ,運行:

試試這個 的telnet [您的服務器的ip] [服務器端口]

您應該會同樣的錯誤 - 拒絕連接。也許服務器實際上並沒有打開端口。或者服務器可能會打開端口,但由於服務器上有防火牆,您無法在另一臺主機上遠程查看它。

而且,在同一臺主機的某個時候能夠揭示更多的線索上運行的客戶端和服務器端的代碼(它應該工作,但如果沒有的話有可能超過1個問題)。