Python enter a hidden password

Question:

I have a python script that I made to update and upgrade my Linux system, it is written in python but after I tell it to update it prompts me to enter a hidden password and I was wondering if there is a way to get Python to enter the hidden password for me. This is my code its simple and works I just need to know if there is a way to enter hidden passwords with python.

import os,sys
os.system("sudo apt-get update && sudo apt-get upgrade")
Asked By: Forge

||

Answers:

There is a std function in python for doing this. See getpass

import getpass
password = getpass.getpass()
Answered By: apparat

You can use the pexpect module. Take a look at this tutorial.

Answered By: bosnjak
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.