Wednesday, March 11, 2020

Its the little things (like opening a web browser)

Sometimes as your developing a solution/script for a problem your faced with interesting challenges where the dumbest workaround (opening a web browser and authenticating with a service) fixes your issue.

Making this simple for a user; who is transitioning mediums (from a cli to a web browser) - this can be interesting technical challenge.

My solution (in python, because that's what I am writing my script in):

    args = parser.parse_args()
    try:
        ### Authenticate with some service, Example below
        ### service = SERVICE(args.server, auth=(username, password)) 
    except SERVICE_Error as e:
        if "ERROR_KEY" in e.text:  # Your key identifier where you know you have 'this one particular issue' 
            print("ERROR: log in to {} using 'incognito' mode in your browser to reset the CAPCHA failed login counter".format(args.server))
            import webbrowser; wb = webbrowser.get()
            if 'chrome' in wb.name:
                wb.remote_args.insert(1, "--incognito")
            elif 'firefox' in wb.name:
                wb.remote_args.insert(1, "--private-window")
            print("INFO: Opening default web-browser in --incognito/--private-window for you! Login to reset the failed log-in counter.")
            print("INFO: After logging in on the web-browser rerun the cli script and authenticate correctly")
            wb.open_new(args.server)

Its the little things (like opening a web browser)

Sometimes as your developing a solution/script for a problem your faced with interesting challenges where the dumbest workaround (opening a ...