2
好傢伙在我的代碼我得到這個堆棧:怪異的「STR」對象不是可調用的蟒蛇
Traceback (most recent call last):
File "main.py", line 30, in <module>
print nova.put_server_metadata("48f366bd-e9c9-47b5-a41f-ca9bcac2d945","labeltest","2.0")
TypeError: 'str' object is not callable
,但我不知道,這個錯誤,我試圖把打印我的方法 「put_server_metadata」 裏面,但它不是在屏幕上打印時,按照代碼:
主要類:
import novaapiclient
import novaauth
if __name__ == "__main__":
nova = novaapiclient.NovaAPIClient("http://192.168.100.142:35357/v2.0/tokens")
nova.makeAuth("adminUser", "secretword", "2ad1fc162c254e59bea043560b7f73cb")
print nova.put_server_metadata("48f366bd-e9c9-47b5-a41f-ca9bcac2d945","labeltest","2.0")
而且我put_server_metadata代碼:
def put_server_metadata(self, serv_id, label, version):
if self.auth.isAuthed():
c = pycurl.Curl()
printer = cStringIO.StringIO()
url = self.auth.getComputeURL() + "/servers/%s/metadata" % serv_id
json_put = file('json_server_put_metadata.json','r+w')
new_js = str(self.put_server_metadata) % (label, version)
json_put.seek(0)
json_put.write(new_js)
json_put.truncate()
json_put.close()
json_to_send = file('json_server_put_metadata.json','r+w')
siz = os.path.getsize("json_server_put_metadata.json")
tok = str(self.auth.getAuthToken())
final_tok = "X-Auth-Token: %s" % tok
content_len = "Content-length: %d" % siz
cont_type = "Content-Type: application/json"
accept = "Accept: application/json"
c.setopt(pycurl.URL, url)
c.setopt(pycurl.PUT, 1)
c.setopt(pycurl.HTTPHEADER, [final_tok, cont_type, accept, content_len])
c.setopt(pycurl.INFILE, json_to_send)
c.setopt(pycurl.INFILESIZE, siz)
c.setopt(pycurl.WRITEFUNCTION, printer.write)
c.setopt(pycurl.VERBOSE, 1)
c.perform()
c.close()
return printer.getvalue()
else:
return "Not authorized"
我的猜測是'nova.put_server_metadata'正在反彈到你沒有顯示的代碼中的字符串。 – geoffspear 2012-04-27 12:39:08