I have verified the existing thread but unable to get the exact reason and resolution of this problem.
PROBLEM: 'sudo: no tty present and no askpass program specified' When code is as follows:
str_command_to_exec += str(each_cmd).strip() + "\n"
# Now execute the command
stdin, stdout, stderr = self.client.exec_command('sudo -S ls')
Below are the possible solutions that I have applied but still no progress.
Sol: Append the Password to command. 'sudo: no tty present and no askpass program specified. bash: line 1: : command not found'
Sol2: stdin, stdout, stderr = client.exec_command(command, get_pty=True) More than 30 seconds still no idea whether control passed from exec_command(...).
Sol3: self.client.get_pty() Unable to setup the connection.
Sol4:
stdin, stdout, stderr = self.client.exec_command('sudo -S ls') stdin.write('\n') stdin.flush() time.sleep(2)
Unable to do the same for sudo command 'stdin, stdout, stderr = self.client.exec_command('sudo -S info')' cause the same PROBLEM.
Can someone please point me if there is any solution to handle Sudo commands or workarounds?