Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a 'NoneType' object?

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) 
like image 613
insecure-IT Avatar asked Jan 13 '14 15:01

insecure-IT


People also ask

What is a NoneType object Python?

NoneType is the type for the None object, which is an object that indicates no value. None is the return value of functions that "don't return anything".

How do you fix a NoneType object in Python?

The TypeError: 'NoneType' object is not iterable error is raised when you try to iterate over an object whose value is equal to None. To solve this error, make sure that any values that you try to iterate over have been assigned an iterable object, like a string or a list.

What causes NoneType?

NoneType in Python is the data type of the object when the object does not have any value. You can initiate the NoneType object using keyword None as follows. Let's check the type of object variable 'obj'. NoneType object indicates no value.

What does NoneType error mean in Python?

NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None . That usually means that an assignment or function call up above failed or returned an unexpected result.


1 Answers

NoneType is the type for the None 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 by re.search when the regex doesn't match, or dict.get when the key has no entry in the dict. You cannot add None to strings or other objects.

One of your variables is None, not a string. Maybe you forgot to return in one of your functions, or maybe the user didn't provide a command-line option and optparse gave you None for that option's value. When you try to add None to a string, you get that exception:

send_command(child, SNMPGROUPCMD + group + V3PRIVCMD) 

One of group or SNMPGROUPCMD or V3PRIVCMD has None as its value.

like image 121
Burhan Khalid Avatar answered Oct 02 '22 03:10

Burhan Khalid