简体   繁体   中英

subprocess call in python, getting error "TypeError: expected str, bytes or os.PathLike object, not NoneType

import subprocess 
import optparse 

def ChangeMac(interface, new_mac):
    print("mac changed")

    subprocess.call(["ifconfig", interface, "down"])
    subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
    subprocess.call(["ifconfig", interface, "up"])

parser =optparse.OptionParser()

parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")
parser.add_option("-m", "--mac", dest="new_mac", help="new MAC address")

(options, arguments) = parser.parse_args()

interface = options.interface
new_mac = options.new_mac

ChangeMac(optoins.interface, options.new_mac)

I am trying to call the function ChangeMac by giving it the variables of interface and new_mac. Although i am getting an error that the second parameter is not a string. Although the user should be first asked what value they want to be entered before the function is even called.

Question is resolved, I needed to add parameters before executing the file. Pretty new to subproccess.

Example: python3 mac_changer.py -i eth0 -m 00:11:22:33:44:55:66

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM