0

I am trying to write a code to fetch data from VM using python.

To start I am trying to ask username and password (not visible or display special character) just how we do in powershell using Get-Credential

I tried below code, it is asking for username but password prompt us not coming

import winrm, getpass
try:
    usrname = input("Enter Username: ")
    passwd = input("Enter Password: ", getpass.getpass())
except Exception as err:
   print('Error Occured : ', err)

Can you please let me know what is wrong. I am using Pycharm to write and execute my code in windows.

4
  • getpass.getpass handles input itself. It doesn't need to be passed to input function. Just use passwd = getpass.getpass('Enter Password: ') Commented Apr 26, 2022 at 14:47
  • @ЕвгенийКрамаров: tried this. but still it is not prompting for password. after entering username when i hit enter, it is blank. Commented Apr 26, 2022 at 14:49
  • 1
    Have you tried referring to this question? Commented Apr 26, 2022 at 14:51
  • Does this answer your question? How to use the Python getpass.getpass in PyCharm Commented Apr 26, 2022 at 20:11

1 Answer 1

1

The input function in Python only takes one argument. To get the password, you can do this :

try:
    usrname = input("Enter Username: ")
    passwd = getpass.getpass("Enter your password: ")
except Exception as err:
   print('Error Occured : ', err)
Sign up to request clarification or add additional context in comments.

2 Comments

tried this. but still it is not prompting for password. after entering username when i hit enter, it is blank.
Can you put some other part of the code ? Such as the way around calling the prompt, if it's a function or something ? Did you try adding breakpoints on PyCharm to see what's happening while runtime ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.