pythonsnowflake-cloud-data-platform

TypeError when creating a Snowflake session using Snowpark and Snowflake Connector


I'm trying to create a Snowflake session using Snowpark and Snowflake Connector in Python. However, I'm encountering a TypeError with the following error message:

TypeError: config() missing 1 required positional argument: 'value'

Here's the relevant code snippet:

import pandas as pd
import boto3 as ab
from snowflake.snowpark.session import Session
import snowflake.connector as sc
import os
from configparser import ConfigParser

config = ConfigParser()
config.read(os.path.dirname(__file__) + str("/DBConn/config.ini"))
cs = config.sections()

connection_parameters = {
    "account": config.get(cs[0], 'account'),
    "user": config.get(cs[0], 'user'),
    "password": config.get(cs[0], 'password'),
    "role": config.get(cs[0], 'defaultrole'),  # optional
    "warehouse": config.get(cs[0], 'defaultwarehouse'),  # optional
    "database": config.get(cs[0], 'defaultdatabase'),  # optional
    "schema": config.get(cs[0], 'defaultschema')  # optional
}

sfSession = Session.builder.config(connection_parameters).create()
print(sfSession)
con = sc.connect(**connection_parameters)
print(con)

I have verified that the configuration parameters are correctly read from the config.ini file. However, when calling the config() method on the Session.builder, it throws a TypeError. It seems like the config() method is expecting an additional positional argument, but I'm unsure what it should be.

I would greatly appreciate any insights or suggestions on how to resolve this issue. Thank you in advance for your help!

Reference URL of Config Parameter from snowflake documentation https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-session

Thanks.

Expecting to establish the session from snowflake using snowpark


Solution

  • config() is expecting key-value pairs, not a dictionary, just modify your code to call config() once for each key-value pair, rather than passing it a dictionary.

    sessionBuilder = Session.builder
    
    for key, value in connection_parameters.items():
        sessionBuilder.config(key, value)
    
    sfSession = sessionBuilder.create()