简体   繁体   中英

Connecting to Snowflake from Python using SSO and browser based sign-in

I'm trying to connect to Snowflake using SSO. I am running the following script (from here ):

import snowflake.connector
ctx = snowflake.connector.connect(
user='<username>',
account='<accountname>',
authenticator='externalbrowser'
)
cs = ctx.cursor()
try:
    cs.execute("SELECT current_version()")
    one = cs.fetchone()
    print(one[0])
finally:
    cs.close()

The only change I have made is passing the authenticator='externalbrowser' argument (see this ) to the connect method instead of password. (user and account cannot be left blank so I'm just putting in dummy strings).

After running the script it displays the following message but a browser tab never appears:

Initiating login request with your identity provider. A browser window should have opened for you to complete the login. If you can't see it, check existing browser windows, or your OS settings. Press CTRL+C to abort and try again...

Not sure if this is relevant, but if I leave it for a few minutes, the script ends with the following error:

snowflake.connector.network.RetryRequest: HTTP 403: Forbidden

I have seen similar questions, but not an answer that would resolve the issue yet.

That <username> likely should be an email address. See https://community.snowflake.com or https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use.html#setting-up-browser-based-sso

With browser-based SSO, the Snowflake-provided client (for example, the Snowflake JDBC driver) needs to be able to open the user's web browser. For this reason, the Snowflake-provided client and the client application that uses it need to be installed on the user's machine . Browser-based SSO does not work if the Snowflake-provided client is used by code that runs on a server.

I assume you have provided the correct user name and password. Now if you are still getting this error, make sure you access the snowflake account using the default browser (which the python program is accessing) and keep your SSO session active.

Now run your python program and it must work.

there is nothing much required and your code parameters looks good

authenticator='externalbrowser'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM