Python 3:通过UNC路径访问Linux下的windows共享

Python 3:通过UNC路径访问Linux下的windows共享,python,unc,Python,Unc,首先,让我们确保windows共享是可访问的: $ sudo mkdir /mnt/test 让我们尝试挂载,但失败: $ sudo mount -t cifs //192.168.0.10/work /mnt/test mount: wrong fs type, bad option, bad superblock on //192.168.0.10/work, missing codepage or helper program, or other error (for sev

首先,让我们确保windows共享是可访问的:

$ sudo mkdir /mnt/test
让我们尝试挂载,但失败:

$ sudo mount -t cifs //192.168.0.10/work /mnt/test
mount: wrong fs type, bad option, bad superblock on //192.168.0.10/work,
   missing codepage or helper program, or other error
   (for several filesystems (e.g. nfs, cifs) you might
   need a /sbin/mount.<type> helper program)

   In some cases useful info is found in syslog - try
   dmesg | tail or so.
现在让我们试试python:

$ python -V
Python 3.5.2+
$ python
>>> import os
>>> os.listdir(r'//192.168.0.10/work')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '//192.168.0.10/work'
$python-V
Python 3.5.2+
$python
>>>导入操作系统
>>>listdir(r'//192.168.0.10/work')
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
FileNotFoundError:[Errno 2]没有这样的文件或目录:“//192.168.0.10/work”
我正在尝试四个斜杠、反斜杠、组合斜杠、带或不带
r
、unicode转义(
字节(路径,“utf-8”)。解码(“unicode_转义”)
),所有这些都会失败,因为
没有这样的文件或目录。失败的原因可能是user/pass,但我无法想象如何将其添加到UNC


另外,我尝试了
pysmb
library,没有用户/通行证也可以正常工作。但是如果可能的话,我不想使用额外的lib。

Python不会“自动”挂载驱动器。在shell中装入windows共享后,您可以通过os.listdir(r'/mnt/test')访问它。我只想通过UNC访问。在我的问题中,只有股份的证明是可以接受的。
$ python -V
Python 3.5.2+
$ python
>>> import os
>>> os.listdir(r'//192.168.0.10/work')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '//192.168.0.10/work'