python - 如何确保输入键没有被输入到密码中

标签 python python-2.7

我遇到以下问题,当 python 脚本运行时,用户在命令窗口上不断按“enter 键”...以下是在命令窗口上运行的内容,但用户不断按 Enter 键,最终会被输入密码和脚本失败,我该如何防止这种情况?

 Parsing the XML

 Building the build combo table

  **Password: //asks for password but user had multiple enter key presses above which is taken as passoword and fails**

Python 代码:-

url='http://wiki.com/'+wikiName+'/w/index.php?title='+hId +'_'+rId+'&action=edit'
cookiehand = urllib2.HTTPCookieProcessor()
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(user=getpass.getuser(),passwd=getpass.getpass(),uri=authhost,realm=realm)
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(auth_handler, cookiehand)
urllib2.install_opener(opener)
# make the request
req = urllib2.Request(url=url)
try:
    f = urllib2.urlopen(req)
    txt = f.read()
    f.close()
except urllib2.HTTPError, e:
    txt = ''
    print 'An error occured connecting to the wiki. No wiki page will be generated.'//eventually gets this error

最佳答案

我认为您应该在读取密码之前尝试刷新用户输入。

为此,请查看 this other post可能有帮助。

关于python - 如何确保输入键没有被输入到密码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13327615/

相关文章:

python - python中任意长度的嵌套字典的组合

python - Pyperclip 复制导致操作系统错误

python - 通过 python 进行多人游戏

python - 将python代码编译成单个exe

python - 将 CSV 数据流转换为 Pandas DataFrame (Python 2.7)

python - Ubuntu - 如何在 Python 3.3 而不是 Python 2.7 上安装 Python 模块 (BeautifulSoup)?

python - 将网络拆分为多个前缀的子网

python阅读整个段落而不是阅读行

python - 如何在python中按单词反转字符串

python - 属性错误 : 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2. 7.11