[Python] Mounting a Windows share on MacOS Sequoia

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    How do I mount a Windows server file share in MacOS in python?

    An error results from this code (MacOS Sequoia, Windows Server 2022, VSCode, python 3.12.6):

    from contextlib import contextmanager
    import os
    import shutil
    import subprocess

    remote_share = '//user:password@10.0.0.100/remote_share_folder'
    local_folder = 'local_folder'

    @contextmanager
    def mounted():
    retcode = subprocess.call(['/sbin/mount_smbfs', remote_share, local_folder])
    if retcode != 0:
    raise OSError("mount operation failed")

    try:
    with mounted():
    shutil.copy(os.path.join(remote_share, 'textfile.txt'), local_folder)
    except OSError as e:
    print(f"Error: {e}")


    Error: mount operation failed mount_smbfs: server connection failed: No route to host
    ​

    Continue reading...

Compartilhe esta Página