Empty Coder
Empty Coder

Reputation: 589

asking for username and password from user using python

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.

Upvotes: 0

Views: 1859

Answers (1)

Ximaz
Ximaz

Reputation: 316

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)

Upvotes: 1

Related Questions