![](/img/trans.png)
[英]TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
[英]Python error - TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
我正在嘗試調試現有腳本,並在運行腳本時收到以下錯誤。 ./check_tandbergvideo CE s 10.50.174.138
此腳本嘗試檢查端點是否已注冊並返回狀態。
追溯(最近一次通話最后一次):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:+不支持的操作數類型:“ 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)
您能否驗證代碼H323的第二行是否具有正確的語法?
這不是腳本中的錯誤。 它只是說TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
,這基本上意味着它不能將None
和"string"
組合在一起。 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.