Python 错误 - TypeError: 不支持 + 的操作数类型:'NoneType' 和 'str'

jav*_*ner 0 python

我正在尝试调试现有脚本,但在运行脚本时出现以下错误。./check_tandbergvideo CE s 10.50.174.138 此脚本尝试检查端点是否已注册或未注册并返回状态。

回溯(最近一次调用):文件“./check_tandbergvideo”,第 156 行,在 main() 文件“./check_tandbergvideo”,第 114 行,在主 EP = getXML(sys.argv[3],sys.argv[1] ]) 文件“./check_tandbergvideo”,第 79 行,在 getXML H323Status = getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Status") + "。错误:" + getElement(tree,xml2+" H323/"+xml2+"Gatekeeper/"+xml2+"Reason")
TypeError: 不支持的操作数类型 +: 'NoneType' 和 'str'

这是引发错误的代码部分。

if model == "CE":
  # SIPStatus =  getElement(tree,xml2+"SIP/"+xml2+"Registration/"+xml2+"Status") + ". Errors: " + getElement(tree,xml2+"SIP/"+xml2+"Registration/"+xml2+"Reason")
    SIPStatus =  str(getElement(tree,xml2+"SIP/"+xml2+"Profile/"+xml2+"Registration/"+xml2+"Status")) + ". Errors: " + str(getElement(tree,xml2+"SIP/"+xml2+"Profile/"+xml2+"Registration/"+xml2+"Reason"))
    H323Status = getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Status") + ". Errors: " + getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Reason")
    ReleaseKey =   getElement(tree,xml2+"SystemUnit/"+xml2+"Software/"+xml2+"ReleaseKey")
    EPModel = getElement(tree,xml2+"SystemUnit/"+xml2+"ProductId")
SWVer =getElement(tree,xml2+"SystemUnit/"+xml2+"Software/"+xml2+"Version")
    else:
    badSyntax()
EPData = {"Model":EPModel,"SIP":SIPStatus,"H323":H323Status,"RK":ReleaseKey,"SW":SWVer}
return(EPData)
Run Code Online (Sandbox Code Playgroud)

您能否验证代码 H323 的第二行是否具有正确的语法?

Ale*_*nov 8

这不是您的脚本中的错误。它只是说TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'这基本上意味着它不能组合None"string"。你应该做str(None)+"string"或设置一些条件if s == None: do something来避免。

  • 究竟为什么要在 `None` 中添加一个字符串?我认为这显然是一种不受欢迎的行为。您只是在安抚错误消息,而不是解决问题。 (2认同)