【问题标题】:How to set root privilege for tarfile module in python?如何在 python 中为 tarfile 模块设置 root 权限?
【发布时间】:2021-11-07 07:08:05
【问题描述】:

这是我的代码:

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 上写入?

【问题讨论】:

    标签: python extract root tar tarfile


    【解决方案1】:

    你不能。相反,运行脚本的用户应该具有 root 权限。在你的例子中是这样的:

    sudo python my_extractor.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-14
      • 2013-05-05
      • 1970-01-01
      • 2020-04-15
      • 1970-01-01
      • 2011-11-19
      • 2013-01-21
      • 1970-01-01
      相关资源
      最近更新 更多