title: Catch Warning in Python 2.7 Without Stopping Part of Progam
body: <p>I'm currently working on a Python program which involves logging in with a username and password. I'm using the <code>getpass</code> module to accomplish this. My problem is that, in the case that getpass is unable to control echo, it spews the following into the terminal before continuing with the program.</p>
  
  <pre><code>Warning (from warnings module):
    File "C:\Python27\lib\getpass.py", line 92
      return fallback_getpass(prompt, stream)
  GetPassWarning: Can not control echo on the terminal.
  Warning: Password input may be echoed.
  </code></pre>
  
  <p>What I'd like to do is catch the warning and print my own custom message instead. The only code I can think of is the following which prevents the traceback from being shown but does not print the custom message at all.</p>
  
  <pre><code>import getpass
  
  try:
      getpass.getpass("Password: ")
  except getpass.GetPassWarning:
      print "Oh no!"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Warning: Password input may be echoed.
  Password: 
  </code></pre>
  
  <p>I'd like to replace the text, <code>Warning: Password input may be echoed.</code>, with my own message ideally.</p>