I'm getting this error when I run my python script:
TypeError: cannot concatenate 'str' and 'NoneType' objects
I'm pretty sure the 'str' means string, but I dont know what a 'NoneType' object is. My script craps out on the second line, I know the first one works because the commands from that line are in my asa as I would expect. At first I thought it may be because I'm using variables and user input inside send_command.
Everything in 'CAPS' are variables, everything in 'lower case' is input from 'parser.add_option' options.
I'm using pexpect, and optparse
send_command(child, SNMPGROUPCMD + group + V3PRIVCMD)
send_command(child, SNMPSRVUSRCMD + snmpuser + group + V3AUTHCMD + snmphmac + snmpauth + PRIVCMD + snmpencrypt + snmppriv)
NoneType
is the type for theNone
object, which is an object that indicates no value.None
is the return value of functions that "don't return anything". It is also a common default return value for functions that search for something and may or may not find it; for example, it's returned byre.search
when the regex doesn't match, ordict.get
when the key has no entry in the dict. You cannot addNone
to strings or other objects.One of your variables is
None
, not a string. Maybe you forgot toreturn
in one of your functions, or maybe the user didn't provide a command-line option andoptparse
gave youNone
for that option's value. When you try to addNone
to a string, you get that exception:One of
group
orSNMPGROUPCMD
orV3PRIVCMD
hasNone
as its value.It means you're trying to concatenate a string with something that is
None
.None is the "null" of Python, and
NoneType
is its type.This code will raise the same kind of error:
In Python, to represent the absence of a value, you can use the
None
valuetypes.NoneType.None