授予访问Python目录的权限

时间:2020-01-21 20:03:03

标签: python directory permissions filesystems os.walk

背景:

我正在运行ABSApp进行情感分析,这需要运行Linux或Mac。我们的网络文件系统需要访问我们的数据集的权限,而我正试图弄清楚如何通过我的代码授予该权限,以便我可以对数据运行预处理脚本并将其存储到网络中,因为我不允许这样做本地存储。我可以通过直接连接到服务器来通过Linux双启动访问文件,但是在运行代码时,该权限不会在系统中传递。

尝试:

我尝试使用 os.walk(dir,topdown = True)访问该目录,当我逐步通过调试器时,看到以下消息:

    top = fspath(top)
    dirs = []
    nondirs = []
    walk_dirs = []

    # We may not have read permission for top, in which case we can't
    # get a list of the files the directory contains.  os.walk
    # always suppressed the exception then, rather than blow up for a
    # minor reason when (say) a thousand readable directories are still
    # left to visit.  That logic is copied here.

当我跳到fspath(path)的定义时,也看不到任何有用的东西。

我阅读了os.access()的文档,但是我已经知道我没有这些文件的权限。它确实在底部说了这一点,但没有告诉我解决方法:

Note

I/O operations may fail even when access() indicates that they would succeed, 
particularly for operations on network filesystems 
which may have permissions semantics beyond the usual POSIX permission-bit model. 

TLDR:

那么,有人在访问和写入需要权限的本地网络服务器上的目录时有任何解决方案吗?我可以做python,java和c ++,所以我愿意接受任何存在的解决方案!预先感谢!

1 个答案:

答案 0 :(得分:0)

已解决:需要在末尾添加noperm才能以写许可权进行挂载

sudo mount.cifs <domain> /home/<mount location>  -o username=<username>,vers=<set accordingly>,noperm