我正在尝试使用以下代码通过SQL炼金术连接到我的 snowflake 帐户。它不起作用,我的猜测是这是因为我们使用Azure AD身份验证登录。任何帮助表示赞赏。
from sqlalchemy import create_engine
engine = create_engine(
'snowflake://{user}:{password}@{account}/'.format(
user='xxx',
password='xxx',
account='xxx'
)
)
try:
connection = engine.connect()
results = connection.execute('select current_version()').fetchone()
print(results[0])
finally:
connection.close()
engine.dispose()
错误信息:
DatabaseError: (snowflake.connector.errors.DatabaseError) 250001 (08001): Failed to connect to DB: QB67303.eu-west-1.snowflakecomputing.com:443. Incorrect username or password was specified.
(Background on this error at: http://sqlalche.me/e/13/4xp6)
这就是我最后的想法。感谢Mike Walton使我步入正轨。
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
engine = create_engine(URL(
account = 'x',
user = 'x',
password = 'x',
database = 'x',
schema = 'x',
warehouse = 'x',
role='x',
authenticator='externalbrowser'
))
try:
connection = engine.connect()
sql_df = pd.read_sql(
"Select top 1 * from a.b",
con=engine
)
finally:
connection.close()
engine.dispose()