0
我已經從另一個類(使用Cherrypy cookies)傳遞了會話對象,並重建了此類中的Nova實例以列出服務器。然而,當我嘗試創建一個服務器列表時,重建的Nova實例可以正常工作,但我有一個屬性錯誤。這種問題很少(我沒有在這個問題上發現任何東西)在互聯網上。 我該如何解決這個問題? :)列表服務器 - OpenStack Nova API
代碼:
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'
正如我在傳遞被分類爲字符串的'sessCookie'?我對此很陌生,因此對我的無能表示歉意,歡呼馬特:) – MRichards
是的,看起來您正嘗試傳遞一個字符串,您實際上需要傳遞一個會話對象。例如,你可以通過使用Python調試器檢查'cherrypy.request.cookie.get('sessCookie').value'的值來驗證,但由於cookie通常是字符串,所以這似乎是一個安全的選擇。 – larsks
我想我明白你的意思,但是當我這樣做時: 'cherrypy.request.cookie.get('name').value',它獲得了名爲'name'的cookie內的值。那麼sessCookie也應該這樣做? 如果有幫助,我已經通過會話對象執行以下操作: 'cherrypy.response.cookie ['sessCookie'] = sess' – MRichards