2010-10-08 23 views
0

那麼,我買了本書Spring Python 1.1,我一直面臨着一些我無法解決的問題。我將編寫每個文件的代碼,以確保一切都清晰。如果你們中的一些人知道什麼是問題,請讓我知道,因爲我很絕望。本書後面的SpringPython錯誤:AttributeError:'module'對象沒有屬性'ObjBase'

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") 

我在終端上運行:蟒蛇simple_server ,然後我得到了以下錯誤:

(:simple_service_server_ctx.py文件):

exporter.after_properties_set() 

,因爲我讀了,它必須聲明(第19行,link to source code)10

(spring)[email protected]:~/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' 

我有我自己的行補充說。

在此先感謝。

回答

1

我想知道你的Pyro版本是什麼。這裏使用Ubuntu 10.04中的Pyro 3.9.1-1,我沒有運行你的代碼的問題。難道你使用的是Pyro 4.x,如果我記得正確的話在這本書發佈後發佈了嗎?

相關問題