[英]Python error - TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
I am trying to debug an existing script and got the below error when I run the script. 我正在尝试调试现有脚本,并在运行脚本时收到以下错误。
./check_tandbergvideo CE s 10.50.174.138
This script tries to check if an endpoint is registered or not registered and returns status. ./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")
追溯(最近一次通话最后一次):main()中的文件“ ./check_tandbergvideo”,第156行,主EP中的文件“ ./check_tandbergvideo”的行,114 = getXML(sys.argv [3],sys.argv [1] ])在getXML H323Status = getElement(tree,xml2 +“ H323 /” + xml2 +“ Gatekeeper /” + xml2 +“ Status”)+“中的文件” ./check_tandbergvideo“,第79行。错误:” + getElement(tree,xml2 +“ H323 /“ + xml2 +” Gatekeeper /“ + xml2 +”原因“)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'TypeError:+不支持的操作数类型:“ NoneType”和“ str”
Here is the part of code that throws the error. 这是引发错误的代码部分。
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)
Could you please verify if the second line of the code H323 has correct syntax? 您能否验证代码H323的第二行是否具有正确的语法?
It's not an error in your script. 这不是脚本中的错误。 It just says
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
that basically means that it can't combine None
and "string"
. 它只是说
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
,这基本上意味着它不能将None
和"string"
组合在一起。 You should do str(None)+"string"
or put some condition if s == None: do something
to avoid. if s == None: do something
应该执行str(None)+"string"
或设置一些条件if s == None: do something
避免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"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.