简体   繁体   English

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

[英]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.

相关问题 类型错误:+= 不支持的操作数类型:'NoneType' 和 'str' - TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str' TypeError:%支持的操作数类型:'NoneType'和'str' - TypeError: unsupported operand type(s) for %: 'NoneType' and 'str' TypeError:+不支持的操作数类型:“ NoneType”和“ str” - TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' TypeError:&:不支持的操作数类型:“ NoneType”和“ str” - TypeError: unsupported operand type(s) for &: 'NoneType' and 'str' Python TypeError:+不支持的操作数类型:'NoneType'和'str' - Python TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' python2 :: TypeError:+:'NoneType'和'str'不受支持的操作数类型 - python2::TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Python TypeError:+不支持的操作数类型:'NoneType'和'str' - Python TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' TypeError:+的不支持的操作数类型:在执行python脚本时为“ NoneType”和“ str” - TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' in executing python script %的Python错误不支持的操作数类型:我的代码为“ NoneType”和“ str” - Python Error unsupported operand type(s) for %: 'NoneType' and 'str' on my code Python 错误:类型错误:+ 不支持的操作数类型:'float' 和 'str' - Python error : TypeError: unsupported operand type(s) for +: 'float' and 'str'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM