[Python] Password value required when using snowflake.connector using key pair authentication...

Discussão em 'Python' iniciado por Stack, Março 11, 2025.

  1. Stack

    Stack Membro Participativo

    This code works in python 3.12 on my laptop but fails on our server which has 3.10

    import os
    import snowflake.connector as sc

    private_key_file = 'pathToKey'
    private_key_file_pwd = os.getenv('pass')


    sql_statement = 'select top 10 items from aTable'

    conn_params = {
    'account': 'ouraccount',
    'user': 'ouruser',
    'private_key_file': private_key_file,
    'private_key_file_pwd':private_key_file_pwd,
    'warehouse': 'ourwh',
    'database': 'ourdb',
    'schema': 'ourschema'
    }

    with sc.connect(**conn_params) as SnowflakeConn:
    cursor = SnowflakeConn.cursor()
    cursor.execute(sql_statement)
    val = cursor.fetchall()

    for item in val:
    print(item)


    the error on 3.10 is


    snowflake.connector.errors.ProgrammingError: 251006: Password is empty
    ​

    if i add a password value to the conn_params with a value as follows

    conn_params = {
    'account': 'ouraccount',
    'user': 'ouruser',
    'password': 'ff',
    'private_key_file': private_key_file,
    'private_key_file_pwd':private_key_file_pwd,
    'warehouse': 'ourwh',
    'database': 'ourdb',
    'schema': 'ourschema'
    }


    Then i get the following error which is expected because the user doesnt have a password because it is using key pair authentication.


    Incorrect username or password was specified.
    ​

    If i look at the documentation here it says that the password param is required.

    How do i get around this in python 3.10?

    Continue reading...

Compartilhe esta Página