sqlalchemy - 使用 Azure AD 身份验证连接到雪花的 SQLAlchemy
问题描述
我正在尝试使用以下代码使用 SQL alchemy 连接到我的雪花帐户。它不起作用,我猜这是因为我们使用 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)
解决方案
虽然这不是使用 sqlalchemy 而是使用本机雪花 sql 连接器,但这对我有用:
import snowflake.connector
ctx = snowflake.connector.connect(
user='<YOUR_USERNAME>',
account='<YOUR_ACCOUNT ; not always needed>',
host='<YOUR SF host, ex: xxxxxx.snowflakecomputing.com / xxxxxx.a0.satoricyber.net>',
authenticator='externalbrowser',
warehouse='<optional>'
)
cs = ctx.cursor()
try:
cs.execute("SELECT * FROM ORGDATA.PUBLIC.CUSTOMERS")
rows = cs.fetchall()
for row in rows:
print(row)
finally:
cs.close()
ctx.close()
推荐阅读
- permissions - 我可以在 AppStore Connect 上授予某人进行 TestFlight 测试的最低权限是多少?
- google-apps-script - 向包含选定用户的 Slack Webhook 发送文本
- regex - ${any_text} 的正则表达式
- c++ - OpenGL 4.3 错误地将第 4 个纹理坐标映射到与第 3 个纹理坐标相同的位置
- concurrency - 在无锁列表之间移动值
- python - 从 mysql AttributeError 创建字典:“元组”对象没有属性“名称”
- c# - 在 DataGridComboBoxColumn 上设置 SelectedItemBinding
- android - ANDROID:如何计算光传感器数据的两个显着变化之间的差异?
- r - 内存问题内存数据帧。写输出的最佳方法?
- android - 将单独编译的类文件添加到 JavaFXPorts apk