我正在尝试创建受密码保护的服务器,但是当我输入密码时,输出不允许我输入密码。所有其他输入都正常工作
getpass
不让我输入。请帮忙
import smtplib, json_store_client, getpass, hashlib, datetime, sys
from termcolor import colored
from time import sleep, ctime
with smtplib.SMTP('smtp.gmail.com',587) as smtp:
smtp.ehlo() #starts email procedure
smtp.starttls() #encrypts
smtp.ehlo() #starts the email procedure again
pw=getpass.getpass(colored("Enter password:\n","green"))
global attemptpw
attemptpw = 0
try:
smtp.login("********@gmail.com",pw)
#**** is my email, I just don’t want to show it
x=chat("[MOD] {} ".format(opt2),True
except:
print(colored("Invalid Admin password","red"))
sleep(1)
else:
print("password entered:",pw)
对于我正在使用的代码:
<强> repl.it
编辑: 我的代码在这里: repl.it/codingandmemes
最佳答案
在 repl.it 中测试了您的原始代码并且它有效,只需在 pw=getpass.getpass(colored("Enter password:\n") 行后面添加
进行验证。print(pw)
即可,“绿色”))
getpass
实现无回声功能 (doc here)这意味着无论您输入什么,它都不会打印在屏幕上,您可能期望小点 (••••••) 代表您输入的每个密码字符,无回显意味着什么都没有,甚至没有小点。
这是在 UNIX 系统上广泛实现的一项功能,旨在增加一点额外的安全性,以便其他人无法得知您的密码长度,请参阅 this post .
关于python - SMTP getpass.getpass() 不接受输入,你能解决这个问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58863650/