python 属性错误:'NoneType'对象没有属性"创建会话"



这段代码看起来像这样,这是一个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),它不返回正确的对象,或者此方法分配结果但不返回对象。检查 SessionMBean 是您正确的对象还是 None。

最新更新