diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
index 62329b759635c431ce1a35e0b76d5991129fe695_bWVyY3VyaWFsL2RlYnVnY29tbWFuZHMucHk=..87e7dd8e77346d80f7c41f7a5dfdd04e305c0048_bWVyY3VyaWFsL2RlYnVnY29tbWFuZHMucHk= 100644
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -3792,6 +3792,10 @@
 def debuguigetpass(ui, prompt=b''):
     """show prompt to type password"""
     r = ui.getpass(prompt)
+    if r is not None:
+        r = encoding.strtolocal(r)
+    else:
+        r = b"<default response>"
     ui.writenoi18n(b'response: %s\n' % r)
 
 
diff --git a/mercurial/mail.py b/mercurial/mail.py
index 62329b759635c431ce1a35e0b76d5991129fe695_bWVyY3VyaWFsL21haWwucHk=..87e7dd8e77346d80f7c41f7a5dfdd04e305c0048_bWVyY3VyaWFsL21haWwucHk= 100644
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -157,6 +157,8 @@
             password = encoding.strfromlocal(password)
         else:
             password = ui.getpass()
+            if password is not None:
+                password = encoding.strfromlocal(password)
     if username and password:
         ui.note(_(b'(authenticating to mail server as %s)\n') % username)
         username = encoding.strfromlocal(username)
diff --git a/mercurial/ui.py b/mercurial/ui.py
index 62329b759635c431ce1a35e0b76d5991129fe695_bWVyY3VyaWFsL3VpLnB5..87e7dd8e77346d80f7c41f7a5dfdd04e305c0048_bWVyY3VyaWFsL3VpLnB5 100644
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1741,7 +1741,7 @@
                         raise EOFError
                     return l.rstrip(b'\n')
                 else:
-                    return getpass.getpass('')
+                    return encoding.strtolocal(getpass.getpass(''))
         except EOFError:
             raise error.ResponseExpected()