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.


1 Answer 1


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.

  • Thanks @JBis. This worked. But I guess something else needs to be done to continue to access the files after the computer has been restarted? Currently, I am not able to access it anymore, the Volume is no longer visible. Sep 28, 2018 at 16:08

You must log in to answer this question.

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