getpass.getpass() function in Python not working?
<p>Running on Windows 7 and using PyCharm 2016.2.3 if that matters at all.</p>

<p>Anyway, I'm trying to write a program that sends an email to recipients, but I want the console to prompt for a password to login.</p>

<p>I heard that <code>getpass.getpass()</code> can be used to hide the input. </p>

<p>Here is my code:</p>

<pre><code>import smtplib
import getpass

import sys

print('Starting...')

SERVER = "localhost"
FROM = "my@email.com"

while True:
    password = getpass.getpass()
    try:
        smtpObj = smtplib.SMTP(SERVER)
        smtpObj.login(FROM, password)
        break
    except smtplib.SMTPAuthenticationError:
        print("Wrong Username/Password.")
    except ConnectionRefusedError:
        print("Connection refused.")
        sys.exit()

TO = ["your@email.com"] 
SUBJECT = "Hello!"
TEXT = "msg text"

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

smtpObj.sendmail(FROM, TO, message)
smtpObj.close()
print("Successfully sent email")
</code></pre>

<p>But when I run my code, here is the output:</p>

<pre><code> Starting...
 /Nothing else appears/
</code></pre>

<p>I know the default prompt for <code>getpass()</code> is <code>'Password:'</code> but I get the same result even when I pass it a prompt string.</p>

<p>Any suggestions?</p>

<p>EDIT: The code continues to run indefinitely after it prints the string, but nothing else appears and no emails are sent.</p>