Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: argument of type 'NoneType' is not iterable in python

Tags:

python

I am trying to get the VM size of a running process and using the following simple script. Here initially I am trying to get the reference of that process. But getting the error as --

if "DomainManager" in c:
TypeError: argument of type 'NoneType' is not iterable

import wmi

computer = wmi.WMI ()

for process in computer.Win32_Process ():

      c = process.CommandLine
      if "DomainManager" in c:
        print c

Would you please let me know the reason.

Thanks, Rag

like image 746
rag Avatar asked Dec 21 '25 23:12

rag


2 Answers

import wmi
computer = wmi.WMI ()

for process in computer.Win32_Process ():
    c = process.CommandLine
    if c is not None and "DomainManager" in c:
        print c

Notice the condition in the if statement:

if c is not None and "DomainManager in c":

This will check to see if c is valid before attempting to check if the given string is a substring of it.

Apparently, some processes have no CommandLine as far as WMI is concerned.

like image 138
agf Avatar answered Dec 24 '25 11:12

agf


It appears

c = process.CommandLine

is setting c equal to None:

In [11]: "DomainManager" in None

TypeError: argument of type 'NoneType' is not iterable

I don't know anything about the Win32 API, so this is a complete guess, but you might try:

if c and "DomainManager" in c:
like image 37
unutbu Avatar answered Dec 24 '25 12:12

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!