I'm currently working on a task where I need to iterate multiple executable file using pefile module the code is look like this
while True:
    try:
        for filename in glob.iglob('C:\Documents and Settings\Zha\Desktop\PE benign\*.exe'):
            pe =  pefile.PE(filename)
            print '%x' % pe.FILE_HEADER.NumberOfSections
    except:
        pass
My intention using try and except is to overcome error raise whenever an executable that raising an error where NT header gives Invalid signature because if I do not use try and except the code will stop at the point where it found an executable with invalid NT header signature
this is what the message looks like if I don't use try and except
PEFormatError: 'Invalid NT Headers signature.' 
However using the code above will cause an infinite loop, is there any possible way to solve this?
 
    