Python Forum

Full Version: need to skip password prompt, continue...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good morning!
I'm scanning a list of hosts to see a host has a specific directory and if not "continue' to the next host.
I thought I would use try/except but it did not work if the host asked for a password the code just stops.
I'd like to 'skip' the host if it prompts for 'username/pass'
here is a try/except snippet:
    try :
        subprocess.call("net use U: /delete /yes")
        subprocess.call("net use U: "+"\\\\"+hnm_sp+"\\C$")      
        print(f" Dir mounted ----- {hnm_sp}")            
    except OSError as st :
        print(f" Mounting Error {hnm_sp}")
        continue
    try :
        if   os.path.exists('\\\\"+hnm_sp+pth_to_file') :  
            print(f" Host Directory found - > {host_path}")    
    except OSError as st :
        print(f" Host does not have Directory -->{hnm_sp}")
        continue  

Thank you.
The issue here is that the python commands (the subprocess.call) are not erroring or throwing any exception that would trigger the except block.

I did see in another forum someone suggested passing an invalid password. That would prevent the prompt, but if the drive was mountable anyway, the mount would succeed. You might see if that would work for you.

net use t: \BOB\helpdesk badpassword /PERSISTENT:NO
You are DA MAN bowlofred!
it works great now!!!
I do not know where you found it - 'badpassword /PERSISTENT:NO'
I was searching the net for more than a day...

Thank you!