Imagine I have the following code:
# -*- coding: utf-8 -*-
from getpass import getpass
#print u'Введите пароль!'.encode('cp866')
passwd = getpass (u'Введите пароль!'.encode('cp866'))
This is for asking user to enter his password in Windows console (thus encoding is 'cp866'). The user sees the following prompt: "???¤?a? ? aR?i!" But if you uncomment the line with print, you will see the correct text. I already have a workaround, first make a print statement, then issue getpass with empty prompt, but I just want to know what exactly is wrong with my code and why do I get this result? One hint if it make it clearer: getpass uses msvcrt.putch (char) to put characters on the console.
putch()
might be doing its own translation from your ANSI codepage (cp1251) to your OEM codepage (cp866). Try encoding with cp1251 instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With