[英]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.