Python Forum
need to skip password prompt, continue...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need to skip password prompt, continue...
#1
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.
Reply
#2
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
tester_V likes this post
Reply
#3
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,619 May-26-2021, 06:21 AM
Last Post: Melcu54
  Automatic user/password entry on prompt by bash script PBOX_XS4_2001 3 2,727 May-18-2021, 06:42 PM
Last Post: Skaperen
  How to skip to a different line while importing a different script kat_gamer 2 2,208 Feb-03-2021, 04:10 AM
Last Post: deanhystad
  How to skip a folder directory in a loop mfkzolo 2 12,362 Nov-18-2020, 07:56 AM
Last Post: mfkzolo
  How to skip LinkedIn signup link using python script? Mangesh121 0 1,766 Aug-26-2020, 01:22 PM
Last Post: Mangesh121
  How to calculate column mean and row skip non numeric and na Mekala 5 4,831 May-06-2020, 10:52 AM
Last Post: anbu23
  Functions, skip an arugment SpongeB0B 2 2,058 Mar-27-2020, 12:10 PM
Last Post: SpongeB0B
  Skip a line doug2019 4 3,118 Oct-09-2019, 06:56 PM
Last Post: ichabod801
  Skip header python_bg1 1 1,955 Jul-25-2019, 01:34 AM
Last Post: ichabod801
  Python: why skip the 'else' if password is wrong Max_988 1 1,933 Jun-20-2019, 12:19 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020