我已经从另一个类传递了会话对象(使用Cherrypy cookies)并在此类中重建了Nova实例以列出服务器。重建的Nova实例可以工作但是当我尝试创建服务器列表时,我有一个属性错误。关于这类问题,互联网上很少(我没有发现像这个问题一样远)。 我该如何解决这个问题? :)
代码:
import cherrypy
import xmlrpclib
import xml.etree.ElementTree as ET
from keystoneauth1 import loading
from keystoneauth1 import session
import novaclient.client as client
from socket import gethostbyaddr
nova = client.Client("2.1", session=cherrypy.request.cookie.get('sessCookie').value)
serverList = nova.servers.list()
print serverList
错误:
File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/lib/python2.7/site-packages/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/cherrypy/lib/jsontools.py", line 61, in json_handler
value = cherrypy.serving.request._json_inner_handler(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "/var/www/frontend/controllers/api/vm.py", line 158, in GET
serverList = nova.servers.list()
File "/usr/lib/python2.7/site-packages/novaclient/v2/servers.py", line 749, in list
"servers")
File "/usr/lib/python2.7/site-packages/novaclient/base.py", line 242, in _list
resp, body = self.api.client.get(url)
File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 173, in get
return self.request(url, 'GET', **kwargs)
File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 89, in request
**kwargs)
File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 331, in request
resp = super(LegacyJsonAdapter, self).request(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 98, in request
return self.session.request(url, method, **kwargs)
AttributeError: 'str' object has no attribute 'request'