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.

  • Can you respond to this? Specially, running from terminal? apple.stackexchange.com/a/120086/263848 – JBis Sep 25 at 4:05
  • Did that command work? – JBis Sep 25 at 17:46
  • Do /Labname in terminal – JBis Sep 25 at 17:53
  • you mean just /Labname ? I get : No such file or directory. – Semihcan Doken Sep 25 at 17:54
  • "except that I use Labname as Volumename" dont – JBis Sep 25 at 18:00
up vote 0 down vote accepted

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:pass@url.com/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. – Semihcan Doken Sep 28 at 16:08

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.