Python getpass 问题请教
各位大佬,在执行问题时候,出现Warning: Password input may be echoed.,如何破解,#APP程序用来处理控制台的输入和输出,因为控制台的操作询问是轮询执行的,所以我们需要在APP使用死循环
from colorama import Fore, Style
from getpass import getpass#遮挡密码
from service.user_service import UserService
import os#系统命令
import sys
import time
__user_service=UserService()
while True:#死循环
os.system("cls") # cls清空内容
print(Fore.LIGHTBLUE_EX, "\n\t=========")
print(Fore.LIGHTBLUE_EX, "\n\t欢迎使用新闻管理系统")
print(Fore.LIGHTBLUE_EX, "\n\t=========")
print(Fore.LIGHTWHITE_EX,"\n\t1.登录系统")
print(Fore.LIGHTWHITE_EX,"\n\t2.退出系统")
print(Style.RESET_ALL)#重置字体颜色
opt=input("\n\t输入操作编号:")
#对输入编号进行判断
if opt=="1":
username=input("\n\t用户名:")
password=getpass("\n\t密码:")##getpass是对密码进行遮挡的库
result=__user_service.login(username,password)
#登录成功
if result==True:
#查询角色是否存在
role=__user_service.search_user_role(username)
os.system("cls")# 确定角色后,清空屏幕,进行下一步
while True:#根据角色进行输出下一步
if role=="新闻编辑":
print("test")
elif role=="管理员":
print(Fore.LIGHTGREEN_EX, "\n\t1.新闻管理")
print(Fore.LIGHTGREEN_EX, "\n\t2.用户管理")
print(Fore.LIGHTRED_EX, "\n\tback.退出登录")
print(Fore.LIGHTRED_EX, "\n\texit.退出登录")
print(Style.RESET_ALL)# 重置颜色
opt = input("\n\t输入操作编号:")
if opt=="back":
break #结束当前循环,返回上一层
elif opt=="exit":
sys.exit(0)# 退出系统
else:
print("\n\t登录失败(3秒自动返回)")
time.sleep(3)
elif opt=="2":
sys.exit(0)#结束当前的循环(最外层),0是代表安全退出
自己顶一下,有大佬解惑吗 getpass在pycharm中不能用,试一下用python终端运行 你是在什么平台上运行
If echo free input is unavailable getpass() falls back to printing a warning message to stream and reading from sys.stdin and issuing a GetPassWarning.
Note
If you call getpass from within IDLE, the input may be done in the terminal you launched IDLE from rather than the idle window itself.
~~ https://docs.python.org/3/library/getpass.html
IDLE (Python),Python集成开发环境
此类整合环境会有此状况,请用命令行模式 zach14c 发表于 2022-3-3 16:06
~~ https://docs.python.org/3/library/getpass.html
IDLE (Python),Python集成开发环境
我直接在pycharm运行的, 用IDLE运行,在IDLE窗口中输入就会提示这样,官方也有说明:
https://docs.python.org/3.1/library/getpass.html
Note If you call getpass from within IDLE, the input may be done in the terminal you launched IDLE from rather than the idle window itself.
sjaben 发表于 2022-3-3 17:28
我直接在pycharm运行的,
在Run/Debug Configurations下,有个Execution,Emulate terminal in output console勾选执行就可以抑制显示了
https://cdn.jsdelivr.net/gh/hututu-tech/IMG-gongfeng@main/2022/03/04/6221c7acc37e2.png pycharm:
在Run/Debug Configurations下,有个Execution,Emulate terminal in output console勾选执行就可以抑制显示了
https://cdn.jsdelivr.net/gh/hututu-tech/IMG-gongfeng@main/2022/03/04/6221c7acc37e2.png
页:
[1]