简体   繁体   English

使用 SSO 和基于浏览器的登录从 Python 连接到 Snowflake

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

I'm trying to connect to Snowflake using SSO.我正在尝试使用 SSO 连接到 Snowflake。 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.我所做的唯一更改是将authenticator='externalbrowser'参数(请参阅this )传递给connect方法而不是密码。 (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.浏览器 window 应该已经打开,您可以完成登录。 If you can't see it, check existing browser windows, or your OS settings.如果看不到,请检查现有浏览器 windows 或您的操作系统设置。 Press CTRL+C to abort and try again...按 CTRL+C 中止并重试...

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 snowflake.connector.network.RetryRequest:HTTP 403:禁止

I have seen similar questions, but not an answer that would resolve the issue yet.我见过类似的问题,但还没有一个可以解决问题的答案。

That <username> likely should be an email address. <username>可能应该是 email 地址。 See https://community.snowflake.com or https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use.html#setting-up-browser-based-sso请参阅https://community.snowflake.comhttps://docs.snowflake.com/en/user-guide/admin-security-f

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.使用基于浏览器的 SSO,Snowflake 提供的客户端(例如,Snowflake JDBC 驱动程序)需要能够打开用户的 web 浏览器。 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.如果运行在服务器上的代码使用 Snowflake 提供的客户端,则基于浏览器的 SSO 不起作用。

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.现在,如果您仍然收到此错误,请确保使用默认浏览器(python 程序正在访问)访问雪花帐户并保持 SSO session 处于活动状态。

Now run your python program and it must work.现在运行您的 python 程序,它必须工作。

there is nothing much required and your code parameters looks good没有什么要求,您的代码参数看起来不错

authenticator='externalbrowser'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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