大家好,我只是 Python 的新手。我想用 Python 编写一个脚本来更改 DNS。
但在编写该代码后,我了解到 resolv.conf 是只读 文件。因为我犯了那个错误:IOError: [Errno 13] Permission denied: '/etc/resolv.conf'
myFile= open("/etc/resolv.conf", "w")
然后,我进行了一些搜索并找到了 os.chmode() 并且我写了一个新行来删除 resolv.conf 的所有权限/strong> 即:
os.chmod("/etc/resolv.conf", 0777)
但现在我正在接受这个错误:IOError: [Errno 13] Permission denied: '/etc/resolv.conf'
我无法克服这个问题,我正在等待您的建议。
谢谢。
请您参考如下方法:
/etc/resolv.conf 通常由 root 所有。除非您的脚本以具有 root privileges 的方式运行,它将无法更改文件。
