使用 xmlrpc & 设置 XML 值Python
我需要设置远程 Linux 机器上存在的 XML 文件中的字段值。如何找出应该连接到哪个端口? 但即使是正确的 ping 也没有发生:
import xmlrpclib
server = xmlrpclib.ServerProxy('http://10.77.21.240:9000')
print server.ping()
print "I'm in hurray"
但我却得到:
Traceback (most recent call last):
File "ping.py", line 3, in <module>
print server.ping()
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 1235, in request
self.send_content(h, request_body)
File "C:\Python26\lib\xmlrpclib.py", line 1349, in send_content
connection.endheaders()
File "C:\Python26\lib\httplib.py", line 892, in endheaders
self._send_output()
File "C:\Python26\lib\httplib.py", line 764, in _send_output
self.send(msg)
File "C:\Python26\lib\httplib.py", line 723, in send
self.connect()
File "C:\Python26\lib\httplib.py", line 704, in connect
self.timeout)
File "C:\Python26\lib\socket.py", line 514, in create_connection
raise error, msg
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it.
我做错了什么?
I need to set the value of a field in an XML file which exists on a remote Linux box. How do I find out which port I should connect to ?
But even a proper ping is not happening:
import xmlrpclib
server = xmlrpclib.ServerProxy('http://10.77.21.240:9000')
print server.ping()
print "I'm in hurray"
bUT instead I got:
Traceback (most recent call last):
File "ping.py", line 3, in <module>
print server.ping()
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 1235, in request
self.send_content(h, request_body)
File "C:\Python26\lib\xmlrpclib.py", line 1349, in send_content
connection.endheaders()
File "C:\Python26\lib\httplib.py", line 892, in endheaders
self._send_output()
File "C:\Python26\lib\httplib.py", line 764, in _send_output
self.send(msg)
File "C:\Python26\lib\httplib.py", line 723, in send
self.connect()
File "C:\Python26\lib\httplib.py", line 704, in connect
self.timeout)
File "C:\Python26\lib\socket.py", line 514, in create_connection
raise error, msg
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it.
What did I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要尝试/考虑的一些事情:
转到远程主机上的命令提示符并键入“
netstat -nap | grep 9000
”。如果您没有返回一些有趣的内容,则意味着端口 9000 上没有任何内容正在运行。您显示远程主机位于 10.77.21.240。这是网络上不可路由的地址(又名私人网络),服务器本身也是如此(不仅仅是你的应用程序)可 ping 通吗?如果您使用的是 Windows,请转到“开始”->“运行并输入“cmd”。在提示符处输入“ping 10.77.21.240”,看看会得到什么。
还有一个想法:该进程可能在可访问的主机上以 9000 启动并运行,但它可能已将端口打开为 127.0.0.1:9000 而不是 0.0.0.0:9000。第一个地址只能由同一台计算机上的进程访问,第二个地址将在该计算机拥有的所有可用 IP 地址上打开端口。
针对评论进行更新:它不应该是一个问题的事实并不能消除它是的可能性。当您调试应该工作但没有工作的东西时,您需要相当迂腐地检查每个步骤,不让自己有任何空间“哦,我知道那个 > 这不可能是问题。” -- 这是口头“挥手”(通常伴随着真实挥手)。您会惊讶地发现问题经常出现在您挥手的区域!进行 ping 测试需要 3 秒。如果它有效,您就继续前进,如果它不起作用...
处理任何系统问题的前三个步骤是:
您必须对食物链中从键盘到应用程序的每一个硬件/软件执行此操作。我猜 80% 的“突然”故障都是第 1 条或第 2 条——是的,确实如此。电缆是一个巨大的痛苦。
与新手通电话时,我通常会先进行长通 - 如果他们可以在浏览器中访问 news.google.com,然后单击随机故事,那么我知道一般情况下网络正常。为什么是新闻?为什么是随机故事?回避浏览器缓存问题。我已经记不清有多少次姐姐给我打电话并宣布“互联网坏了!”我们做的第一件事是谷歌新闻测试。 99% 的时间它都有效,所以我让她启动反向 WinVNC(UltraVNC 的 SingleClick 是天赐之物),我进入她的机器,然后我们就可以看到真正的问题是什么。
如果长传不起作用,那么我看看他们是否可以到达他们的路由器。等等等等。
A couple of things to try / think about:
Go to a command prompt on the remote host and type "
netstat -nap | grep 9000
". If you don't get back something interesting it means that nothing is running at port 9000.You show the remote host at 10.77.21.240. This is an unroutable address on the net (AKA Private Network), so is the server itself (not just your app) pingable? If you are on windows, goto Start -> Run and type "cmd". At the prompt type, "ping 10.77.21.240" and see what you get.
One more thought: the process may be up and running at 9000 on a reachable host, but it may have opened the port as 127.0.0.1:9000 instead of 0.0.0.0:9000. The first address will only be reachable by processes on the same machine, the second one will open the port on all available IP addresses the machine has.
Update in response to comment: The fact that it shouldn't be a problem doesn't eliminate the possibility it is. When you are debugging something that should be working, but isn't, you need to get fairly pedantic about checking each step, allowing yourself no room for 'Oh, I know that couldn't be the problem.' -- this is a verbal 'handwave' (often accompanied by a real handwave). You'd be surprised how often the problem exists in exactly the area you are handwaving! It takes 3 seconds to do the ping test. If it works, you move on, if it doesn't work ...
The first three steps in dealing with any system problem are:
And you have to do this for each and every piece of hardware/software in the food chain from your keyboard to the app. I'd guess 80% of 'sudden' failures are items 1 or 2 -- yes, really. Cables are a huge pain in the ass.
When on the phone with novices I normally start by going for the long pass -- if they can get news.google.com in a browser and then click on a random story, then I know that in general the network is OK. Why the news and why a random story? To sidestep browser cache issues. I've lost count of the number of times my older sister has called me up and announced "The Internet is broken!" The first thing we do is the google news test. 99% of the time it works, so I have her fire up reverse-WinVNC (UltraVNC's SingleClick is a God-send), I get on her machine, and then we see what the real problem is.
If the long pass doesn't work, then I see if they can get to their router. Etc. etc.