我正在使用 VMware API 来执行 vCenter 操作。使用 suds 进行 SDK 调用。我的 vCenter 配置为非英语(日语)支持。
import suds
client = suds.client.Client("http://localhost/sdk/vimService.wsdl", location="https://localhost/sdk")
mo = suds.sudsobject.Property("ServiceInstance")
mo._type = "ServiceInstance"
service_content = client.service.RetrieveServiceContent(mo)
try:
client.service.Login(service_content.sessionManager, username='test', password='test', locale='en_US')
var = client.factory.create('ns0:WaitOptions')
kwargs = {'maxWaitSeconds': "2", 'maxObjectUpdates': "3"}
[setattr(var, key, value) for key, value in kwargs.items()]
client.service.WaitForUpdatesEx(service_content.propertyCollector, version=1, options=var)
except suds.WebFault as e:
print e.args
如果我不设置locale,那么vCenter中是否出现任何错误,它将以非英文文本返回您。我设置locale和异常将以英语返回。
我们设置了 alocale并且它的工作正常,session但是如果在会话创建中有任何错误或会话超时,那么它会以非英语形式给出错误。
请检查此代码(没有 create 的调用方法session)
...
...
mo._type = "ServiceInstance"
service_content = client.service.RetrieveServiceContent(mo)
try:
var = client.factory.create('ns0:WaitOptions')
kwargs = {'maxWaitSeconds': "2", 'maxObjectUpdates': "3"}
[setattr(var, key, value) for key, value in kwargs.items()]
client.service.WaitForUpdatesEx(service_content.propertyCollector, version=1, options=var)
except suds.WebFault as e:
print e.args
输出 :
(u"Server raised fault: '\u30bb\u30c3\u30b7\u30e7\u30f3\u304c\u8a8d\u8a3c\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002'",)
翻译 :
(u"Server raised fault: 'セッションが認証されていません。'",)
# English
(u"Server raised fault: 'Session is not authenticated.',)
有什么方法可以locale在 wsdl url中设置http://localhost/sdk/vimService.wsdl?local=en_US吗?