I have a NAS device that appears in Finder under the Shared devices so I can read and write to it just like any folder on my OSX drive with no need to provide authentication. How can I read and write to it from Python code? I have tried manually accessing required folders on the drive so that they then appear in Volumes, but I still can't get at them.

closed as off-topic by Allan, Nimesh Neema, IconDaemon, nohillside Jan 21 at 7:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development are off-topic here, but can be asked on Stack Overflow." – Allan, Nimesh Neema, IconDaemon, nohillside
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you clarify this slightly? Are you trying to mount the network shares via python, or are you just trying to read/write to already mounted shares? What happens when you use os.chdir() to select a filepath on the shares as the current working dir? – benwiggy Jan 20 at 11:10
  • I think what I am missing is what is the filepath to use for the NAS box that is already being shared with OSX – THobson Jan 20 at 11:31
  • How did you manually access them? – Mark Jan 20 at 15:24
  • I just click on them in Finder (under Shared - not Devices) – THobson Jan 20 at 16:06

If you want to mount the network volume (or make sure that it is mounted) from the python code, then you could use the shell command mount, from inside an os.system() call. See this answer.

Once mounted, you can access the contents of the drive like any other connected drive with a filepath under /Volumes. It is likely to be something like: /Volumes/My\ NAS/path/to/file (where "My NAS" is the name of your share.)

Note that whether the Finder shows the drive under "Devices" or "Shared" is irrelevant.

If you need to find the filepath for a given item on the NAS, use Command Alt C in the Finder to copy the filepath to the clipboard as text.

If the correct path still isn't working in your python, then we need to see your python code.

  • Command Alt C works fine for items listed under Devices in Finder (thanks I didn't know that) but doesn't seem to do anything for devices listed under Shared, which is where my NAS box is. – THobson Jan 20 at 12:21
  • 1
    Have you tried an actual path to a file or folder on the device, rather than the device itself? – benwiggy Jan 20 at 12:39
  • The problem is I don't know the path to the device. Do I need to use its IP address? Finder doesn't seem to need it. – THobson Jan 20 at 13:01
  • 1
    So when you select a file on the device in the Finder, and press Command Alt C, what filepath do you get? – benwiggy Jan 20 at 13:55
  • 1
    That doesn't matter. If the device is mounted, then "/Volumes/LaCie 4Tbt/folder/folder/myfile.ext" is a valid filepath that should work in python. You should also be able to navigate and work with files on this path in the Terminal. – benwiggy Jan 20 at 16:40

Not the answer you're looking for? Browse other questions tagged .