我需要使用SQLAlchemy连接到雪花,但诀窍是,我需要使用OAuth2进行身份验证。雪花文档只描述使用用户名和密码进行连接,这不能在我构建的解决方案中使用。我可以使用雪花的python连接器进行身份验证,但我看不到如何使用SQLAlchemy粘合它的简单路径。在为此编写自定义接口之前,我想知道是否有现成的解决方案。
发布于 2021-12-06 09:30:54
使用snowflake.connector.connect创建到数据库- 见文件的PEP-249连接。然后使用param creator of create_engine (文档) -它需要一个可调用的,返回PEP-249连接。如果使用它,则忽略URL param。
示例代码:
def get_connection():
return snowflake.connector.connect(
user="<username>",
host="<hostname>",
account="<account_identifier>",
authenticator="oauth",
token="<oauth_access_token>",
warehouse="test_warehouse",
database="test_db",
schema="test_schema"
)
engine = create_engine("snowflake://not@used/db", creator=get_connection)https://stackoverflow.com/questions/70228997
复制相似问题