How to access files on a networked smb server with Python on macOS

I have a bunch of files that sit on a networked drive to which I can connect by using Finder > Go > Connect to Server and entering the address smb://smb-name.institute.name.org/DRIVENAME and then entering my credentials. How I connect to the shared folders/files

But I need to connect to this from Python so I can run Python code that analyzes those files. How can I do so?

So far I tried the answer here but nothing seems to happen when I do this. (I do not need to copy or clone the files over to my computer, I just need to access them from Python so perhaps this is not the right thing to do anyway.)

I also found this by Googling but am getting a ConnectionRefused error when I execute the line assert conn.connect(server_ip, 139) where I set server_ip to be the URL I used to connect my Mac or a "gaierror: [Errno 8] nodename nor servname provided, or not known" depending on if I enter just the beginning part or the whole URL.

I would appreciate any help as I am new to smb, networking and all of this and connecting to a networked drive with Python on a Mac.


After discussing in chat the OP was able to solve the issue by creating a mount point.

  1. sudo mkdir /Volumes/test
  2. sudo mount_smbfs //user:[email protected]/folder /Volumes/Test

This can be done with python by eliminating the sudo but running the script/application as admin.