From d6fcc223b8f8ecd61360c991d448f3a2203fd4a2 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 10 Aug 2023 17:54:26 +0300 Subject: [PATCH] ssh: catch EOFError from getpass If getpass is unable to get input from stderror or stdin, it will raise this error. Similar to how we do it in dvc https://github.com/iterative/dvc/blob/04e891cef929567794ade4e0c2a1bf399666f66e/dvc/ui/__init__.py#L268 --- dvc_ssh/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dvc_ssh/__init__.py b/dvc_ssh/__init__.py index 7097d25..057c9e2 100644 --- a/dvc_ssh/__init__.py +++ b/dvc_ssh/__init__.py @@ -13,9 +13,13 @@ @wrap_with(threading.Lock()) @memoize def ask_password(host, user, port, desc): - return getpass.getpass( - f"Enter a {desc} for " f"host '{host}' port '{port}' user '{user}':\n" - ) + try: + return getpass.getpass( + f"Enter a {desc} for " + f"host '{host}' port '{port}' user '{user}':\n" + ) + except EOFError: + return None # pylint:disable=abstract-method