import pexpect, sys
pwd = getEncryptedPassword()
cmd = 'yourcommand'
sCmd = pexpect.spawn('sudo {0}'.format(cmd))
sCmd.logfile_read = sys.stdout
sCmd.expect('Password:')
sCmd.sendline(pwd)
sCmd.expect(pexpect.EOF)
Fabric Sudo No Password Solution