python - 如何在 python 中为 tarfile 模块设置 root 权限?
问题描述
这是我的代码:
gitlab_restore = tarfile.open("PATH/gitconf.tar")
gitlab_restore.extract("/opt/destination/path")
gitlab_restore.close()
当我运行它时发生了这个错误
2021-11-07 09:44:37,139 - root - ERROR - [Errno 13] Permission denied: '/opt/destination/path'
如何设置 tarfile 模块的 root 权限以在 /opt 上写入?
解决方案
你不能。相反,运行脚本的用户应该具有 root 权限。在你的例子中是这样的:
sudo python my_extractor.py
推荐阅读
- javascript - 检查当前文档是否保存
- html - 仅使用引导程序在移动设备上将 div 显示为侧边栏
- java - 使用夏令时将当前日期时间转换为罗马尼亚时间
- javascript - 如何为 vue 组件加载动态模板?
- django - 为什么函数可以返回函数本身
- flutter - Flutter:在导航时,secondaryAnimation 做了什么?
- laravel - 在 laravel 中设计一个特定的情况(多对多关系)
- sql - 如果相关字段具有相同的值,则 Sql 岛和间隙合并连续记录
- python - 从 .msg 文件中读取
- javascript - botframework v4:在 channelData 属性中发送松弛块不起作用