【问题标题】:Unable to extract the tar file in python because of permission issue由于权限问题,无法在 python 中提取 tar 文件
【发布时间】:2019-02-27 10:19:49
【问题描述】:

我无法在 python 中提取 tar 文件。

这是我用来在 Python 中提取 tar 文件的代码库。

file_path = os.path.join(extracted_tar_files, file.strip('.tar'))
tf = tarfile.open(os.path.join(files_directory, file))
tf.extractall(file_path)
tf.close()

一些 tar 文件运行良好。一些 tar 文件出现以下错误。

*** PermissionError: [Errno 13] Permission denied: '\home\piercer\etc.sudoers'

你能帮帮我吗?谢谢!

【问题讨论】:

  • 这似乎是 Unix 问题而不是 Python 问题。为什么不尝试使用tar 在命令行中提取并修复权限?
  • @firefrorefiddle 这在普通 Windows WinZip 模块上工作。我需要在 python 中进行这种提取

标签: python-3.x python-2.7 tarfile


【解决方案1】:

该文件似乎属于其他人,而您似乎没有读取权限。正如 sudoers 文件所预期的那样。您可以更改权限:

$ sudo -E chown $USER /home/piercer/etc.sudoers

【讨论】:

  • 我用的是windows 10,上面的命令好像是linux命令,能不能分享一下windows命令。谢谢!
【解决方案2】:
tar.extractall(file_path, numeric_owner=True) 

这将由运行脚本的用户创建文件所有者。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。
猜你喜欢
  • 1970-01-01
  • 2014-05-30
  • 1970-01-01
  • 1970-01-01
  • 2019-12-14
  • 2013-03-03
  • 2020-10-17
  • 1970-01-01
  • 2014-11-26
相关资源
最近更新 更多