[英]AttributeError: 'NoneType' object has no attribute 'findAll' - Python
[英]python AttributeError: 'NoneType' object has no attribute 'createSession
这段代码看起来像这样,这是一个python脚本
我认为这是错误蔓延的地方
def getSessionManagementMBean(sessionName):
SessionMBean = findService("SessionManagement", "com.bea.wli.sb.management.configuration.SessionManagementMBean")
SessionMBean.createSession(sessionName)
return SessionMBean
当我们运行脚本时,我们遇到了这个错误
File "/var/cache/chef/weblogic/managed/config-setup/smtpConfig/import.py", line 190, in getSessionManagementMBean
AttributeError: 'NoneType' object has no attribute 'createSession
我正在考虑用此替换上面的代码
def getSessionManagementMBean(sessionName):
SessionMBean = findService("SessionManagement", "com.bea.wli.sb.management.configuration.SessionManagementMBean")
Variable = SessionMBean.createSession(sessionName)
print Variable
return Variable
欢迎任何解决方案或意见
def getSessionManagementMBean(sessionName):
SessionMBean = findService("SessionManagement",
"com.bea.wli.sb.management.configuration.SessionManagementMBean")
if SessionMBean: # check SessionMBean is not 'None'
SessionMBean.createSession(sessionName)
return SessionMBean
# if SessionMBean is 'None' or 0 then raise your own exception
raise Exception("Something happened with SessionMBean")
也许您有一个方法(findService),它没有返回正确的Object,或者该方法分配了结果,但没有返回对象。 检查SessionMBean是您的正确对象还是None。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.