Python Forum
need to skip password prompt, continue... - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: need to skip password prompt, continue... (/thread-35318.html)



need to skip password prompt, continue... - tester_V - Oct-19-2021

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.


RE: need to skip password prompt, continue... - bowlofred - Oct-19-2021

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


RE: need to skip password prompt, continue... - tester_V - Oct-19-2021

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!