Can you move the  'import pwd' line to the try/except block above? 
The pwd module doesn't exist on Windows and this will cause a stacktrace on Windows.