简体   繁体   English

如何使用 SSO(sqlalchemy)将 python 连接到雪花?

[英]How to connect python to Snowflake using SSO (sqlalchemy)?

I recently had to enable SSO with Okta and had a few python projects I was running in Google Colab.我最近不得不使用 Okta 启用 SSO,并且在 Google Colab 中运行了一些 python 项目。

I am trying to redesign the connection string but can't seem to get it right.我正在尝试重新设计连接字符串,但似乎无法正确处理。

This was my initial connection string before SSO:这是我在 SSO 之前的初始连接字符串:

from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

engine = create_engine(URL(
    account = acc,
    user = usr,
    password = psw,
    warehouse = whs,
    role = rol
))
engine.connect()

This is what I found from research it should be with SSO:这是我从研究中发现的,它应该与 SSO 一起使用:

from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine

engine = create_engine(URL(
    account = acc,
    user = usr,
    password = psw,
    warehouse = whs,
    role = rol
),
connect_args={
        'authenticator': 'https://myokta.okta.com/',
        }
)
engine.connect()

I tried that but I am getting this error:我试过了,但我收到了这个错误: 在此处输入图像描述

I also tried using {'authenticator': 'externalbrowser'} but because I am in Google Colab I get an error stating Unable to open a browser in this environment.我也尝试使用{'authenticator': 'externalbrowser'}但因为我在 Google Colab 中,我收到一条错误消息,指出Unable to open a browser in this environment. . .

The Web UI is working for the same user so it's just in Colab that I am having this issue. Web UI 为同一用户工作,所以只是在 Colab 中我遇到了这个问题。

How should I go about to connect?我应该如何连接 go ?

EDIT: So after doing some research I found that because we have MFA enabled this would not work.编辑:所以在做了一些研究之后,我发现因为我们启用了 MFA,所以这不起作用。 Is it possible to then use:是否可以使用:

engine = create_engine(URL(
    account = acc,
    user = usr,
    warehouse = whs,
    role = rol,
    authenticator = 'externalbrowser'
))
engine = engine.connect()

And have the externalbrowser be an iframe in the same notebook?并且externalbrowser浏览器是否是同一笔记本中的 iframe?

I managed to find the solution.我设法找到了解决方案。 When running engine.connect() with authenticator='externalbrowser' and Google Collab cannot open a separate tab, it will provide a manual link, which, when clicked, opens another tab pointing to localhost URL with a token as a param.当使用authenticator='externalbrowser'运行engine.connect()并且 Google Collab 无法打开单独的选项卡时,它将提供一个手动链接,单击该链接会打开另一个指向localhost URL 的选项卡,其中包含一个令牌作为参数。 I then copy this URL and when going back to the notebook, I paste this URL to the input box opened in the cell.然后我复制这个 URL 并在回到笔记本电脑时,将这个 URL 粘贴到单元格中打开的输入框中。

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

相关问题 如何使用 Python(SSO 身份验证)在 Snowflake 中查询? - How to querying in Snowflake using Python (SSO Authentication)? 如何使用 OAuth2 将 SQLAlchemy 连接到 Snowflake 数据库? - How to connect SQLAlchemy to Snowflake database using OAuth2? Python:如何使用 Apache Beam 连接到 Snowflake? - Python: How to Connect to Snowflake Using Apache Beam? Snowflake - 如何使用 NodeJS 连接到 Snowflake - Snowflake - how to connect to Snowflake using NodeJS 如何在 Python 3 中的 Databricks 中使用 python 雪花连接器连接到雪花? - How to connect to Snowflake using python snowflake connector from within Databricks in Python 3? 使用密钥对身份验证的雪花 SQLAlchemy engine.connect() 失败 - SQLAlchemy engine.connect() fails for Snowflake using keypair authentication 如何使用 Python vscode 中的多个 SQL 代码连接到雪花? - How to connect to snowflake using multiple SQL code in Python vscode? 我们如何使用 python 连接器连接到雪花 - How do we connect to snowflake using python connector 如何在不使用 snowflake-connector-python 的情况下连接到 aws lambda function 中的雪花? - How can I connect to snowflake in aws lambda function without using snowflake-connector-python? 使用 SSO 通过 Python 连接到 SAP HANA - Connect to SAP HANA with Python using SSO
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM