我正在编写一个脚本来登录 Hotmail。它要求用户输入密码,如果他们输入正确的密码,一切都很好。
但是,如果他们第一次输入错误的密码,则有效密码将在后续尝试中无效。
这是我用于用户输入密码的内容:
import poplib
M = poplib.POP3_SSL('pop3.live.com', 995) #Connect to hotmail pop3 server
M.set_debuglevel(2)
success = False;
user = "email@hotmail.com"
while success == False:
try:
password = raw_input("password: ")
M.user(user)
M.pass_(password)
except:
print "Invalid credentials"
else:
print "Successful login"
success = True
这是调试级别 2 的输出:
$ python my_program.py
password: password
*cmd* 'USER email@hotmail.com'
*put* 'USER email@hotmail.com'
*get* '+OK password required\r\n'
*resp* '+OK password required'
*cmd* "PASS password"
*put* "PASS password"
*get* '+OK mailbox has 1 messages\r\n'
*resp* '+OK mailbox has 1 messages'
Successful login
$ python my_program.py
password: 1234
*cmd* 'USER email@hotmail.com'
*put* 'USER email@hotmail.com'
*get* '+OK password required\r\n'
*resp* '+OK password required'
*cmd* 'PASS 1234'
*put* 'PASS 1234'
*get* '-ERR authentication failed\r\n'
*resp* '-ERR authentication failed'
Invalid credentials
password: password
*cmd* 'USER email@hotmail.com'
*put* 'USER email@hotmail.com'
*get* '+OK password required\r\n'
*resp* '+OK password required'
*cmd* "PASS password"
*put* "PASS password"
Invalid credentials
我在这里想念什么?我应该注意,我对 python 很陌生。