Python error-TypeError:不支持+的操作数类型:“NoneType”和“str”

2024-05-15 11:01:01 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Traceback (most recent call last): File "./check_tandbergvideo", line 156, in main() File "./check_tandbergvideo", line 114, in main EP = getXML(sys.argv[3],sys.argv[1]) File "./check_tandbergvideo", line 79, in getXML H323Status = getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Status") + ". Errors: " + getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Reason")
TypeError: unsupported operand type(s) for +: 'NoneType' and '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)

请验证代码H323的第二行语法是否正确?


Tags: 脚本treecheckstatuslineregistrationgatekeeperfile
2条回答

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

非常感谢大家的宝贵意见…我试过了,而且成功了。

H323Status = str(getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Status")) + ". Errors: " + str(getElement(tree,xml2+"H323/"+xml2+"Gatekeeper/"+xml2+"Reason"))

相关问题 更多 >