【问题标题】:xml-rpc python doesn't print outputxml-rpc python 不打印输出
【发布时间】:2011-12-15 21:32:53
【问题描述】:

我正在尝试让 IBM tutorialworks 示例运行,但到目前为止还没有任何运气

服务器:

import calendar, SimpleXMLRPCServer

#The server object
class Calendar:
    def getMonth(self, year, month):
        return calendar.month(year, month)

    def getYear(self, year):
        return calendar.calendar(year)


calendar_object = Calendar()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(calendar_object)

#Go into the main listener loop
print "Listening on port 8888"
server.serve_forever()

客户:

import xmlrpclib

server = xmlrpclib.ServerProxy("http://localhost:8888")

month = server.getMonth(2002, 8)
print month

它应该打印出一个日历,但它只是在我运行客户端时停止并且只打印出“Listening on port 8000”

我使用的是 python 2.7.2,但教程是在 2002 年 9 月编写的。是否存在某种语法差异或我做错了什么。

教程本身位于此处http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html

提前致谢!

【问题讨论】:

  • 服务器代码看起来不错。客户端在哪里运行?以防万一,请尝试在 URL 上添加斜杠。
  • 刚刚从一个文件夹运行服务器,然后也运行了 client.py。现在 client.py 什么都没有显示,只是在闲置。
  • 我刚刚检查过了。代码在我的 OSX Leapord 和 python 2.6.1 上运行得非常好

标签: python xml-rpc simplexmlrpcserver


【解决方案1】:

我的猜测是某些东西阻止了您的服务器进程中对端口 8888 的低级 bind 调用。如果可以,请以 root 身份运行 netstat -tlp。如果不能,请使用telnet localhost 8888 看看是否有任何东西在监听。

【讨论】:

  • 已检查,8888 端口没有使用 将客户端和服务器中的端口更改为 8000,然后将它们改回 8888,现在一切正常:/
  • adobe 激活使用端口 8888 并且干扰了 python 代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-09
  • 1970-01-01
  • 2018-03-08
  • 1970-01-01
  • 2011-01-16
相关资源
最近更新 更多