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
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()
Please ensure you are using the latest snowpark release and that you are passing a dictionary with key-value pairs (both must be strings!!)
The Session.builder.config
should recognize a dictionary passed as unique argument as stated in the documentation:
To create the session:
- Create a Python dictionary (dict) containing the names and values of the parameters for connecting to Snowflake.
- Pass this dictionary to the Session.builder.configs method to return a builder object that has these connection parameters.
- Call the create method of the builder to establish the session.
https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-session
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.