When I am tryibg to change Mac Address through python code this message occurred "a password is required"

Viewed 75

When I am trying to run this below code:

import subprocess

subprocess.call(["sudo", "ifconfig", "eth0", "down"])
subprocess.call(["sudo", "ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55"])
subprocess.call(["sudo", "ifconfig", "eth0", "up"]) 

The error mentioned below occurred:

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

sudo: a password is required

1 Answers

You are trying to run the command sudo. This command requires the user to insert a password. Since you are running it from a script, it cannot receive the password. You should instead run the command without sudo and run the entire python script with sudo

Related