def login(account_name, region, username, password, passcode): # Data to be sent in the request body data = { "data": { "ACCOUNT_NAME": account_name, "LOGIN_NAME": username, "PASSWORD": password, "CLIENT_APP_ID": "Snowflake UI", "CLIENT_APP_VERSION": 20231219004219, "EXT_AUTHN_DUO_METHOD": "passcode", "PASSCODE": passcode, } } # Convert the data to JSON data_json = json.dumps(data).encode("utf-8") # Headers headers = { "Content-Type": "application/json", } # Create a connection - replace with proxy details if needed url = f"https://{account_name}.{region}.snowflakecomputing.com/session/v1/login-request?__uiAppName=Login" req = urllib.request.Request(url, data=data_json, headers=headers, method="POST") # Perform the request and extract the 'redirectURI' try: with urllib.request.urlopen(req) as response: print(response) response_data = json.loads(response.read().decode()) data2 = { "data": { "CLIENT_APP_ID": "Snowflake UI", "CLIENT_APP_VERSION": 20231219004219, }, "inFlightCtx": response_data["data"]["inFlightCtx"] } # Convert the data to JSON again data_json2 = json.dumps(data2).encode("utf-8") req2 = urllib.request.Request(url, data=data_json2, headers=headers, method="POST") with urllib.request.urlopen(req2) as response2: print(response2) response_data2 = json.loads(response2.read().decode()) return response_data2["data"]["redirectURI"] except urllib.error.URLError as e: print(e.reason)