本书后面的SpringPython错误:AttributeError:'module'对象没有属性'ObjBase'

时间:2010-10-08 10:32:45

标签: python spring

好吧,我买了Spring Python 1.1这本书,我遇到了一些我无法解决的问题。我将编写每个文件的代码,以确保一切都清楚。如果你们中的一些人知道这是什么问题,请告诉我,因为我很绝望。

simple_service.py

class Service(object):
def happy_birthday(self, name):
    results = []
    for i in range(4):
        if i <= 2:
            results.append("Happy birthday dear %s!" % name)
        else:
            results.append("Happy birthday to you!")
            return results

simple_service_server_ctx.py

from springpython.config import *
from springpython.remoting.pyro import *

from simple_service import *

class HappyBirthdayContext(PythonConfig):
    def __init__(self):
        PythonConfig.__init__(self)

    @Object
    def target_service(self):
        return Service()

    @Object
    def service_exporter(self):
        exporter = PyroServiceExporter()
        exporter.service = self.target_service()
        exporter.service_name = "service"
        exporter.service_host = "127.0.0.1"
        exporter.service_port = "7766"
        exporter.after_properties_set()
        return exporter

simple_server.py

from springpython.context import *
from simple_service_server_ctx import *

if __name__ == "__main__":
    ctx = ApplicationContext(HappyBirthdayContext())
    ctx.get_object("service_exporter")

我在终端上运行:python simple_server 然后我收到以下错误:

(spring)kiko@kiko-laptop:~/examples/spring$ python simple_server.py 
Traceback (most recent call last):
  File "simple_server.py", line 6, in <module>
    ctx = ApplicationContext(HappyBirthdayContext())
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/context/__init__.py", line 45, in __init__
    self.get_object(object_def.id, ignore_abstract=True)
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/container/__init__.py", line 80, in get_object
    comp = self._create_object(object_def)
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/container/__init__.py", line 129, in _create_object
    self._get_constructors_kw(object_def.named_constr))
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/factory/__init__.py", line 62, in create_object
    return self.method()
  File "<string>", line 2, in service_exporter
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/config/__init__.py", line 1370, in object_wrapper
    return _object_wrapper(f, theScope, parent, log_func_name, *args, **kwargs)
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/config/__init__.py", line 1350, in _object_wrapper
    return _deco(f, scope, parent, log_func_name, *args, **kwargs)
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/config/__init__.py", line 1345, in _deco
    results = f(*args, **kwargs)
  File "/home/kiko/examples/spring/simple_service_server_ctx.py", line 22, in service_exporter
    exporter.after_properties_set()
  File "/home/kiko/.virtualenvs/spring/lib/python2.6/site-packages/springpython/remoting/pyro/__init__.py", line 58, in after_properties_set
    pyro_obj = Pyro.core.ObjBase()
AttributeError: 'module' object has no attribute 'ObjBase'

我已经添加了自己的行(文件:simple_service_server_ctx.py):

exporter.after_properties_set()

因为我读到必须声明它(第19行,link to source code)。

提前致谢。

1 个答案:

答案 0 :(得分:1)

我想知道你的Pyro版本是什么。这里使用Ubuntu 10.04中的Pyro 3.9.1-1,我在运行代码时没有任何问题。可能是你正在使用Pyro 4.x,如果我记得正确的是在该书出版后被释放了吗?