0

Here is my Snowflake connection in Python:

import snowflake.connector
ctx = snowflake.connector.connect(user='someuser@somedomain.com',
password='somepassword',
account='someaccount',
warehouse='somewarehouse',
database='somedb',
schema='someschema'
authenticator='someauth')

It works fine, but now I need to store my connection details in Azure Key Vault and is far as I understand it will be coming back as a string, which I will need to feed into snowflake.connector.connect()

So I tried to convert connection parameters into string:

connection_string = "user=someuser@somedomain.com;password=somepassword;account=someaccount;authenticator=someauth;warehouse=somewarehouse;database = somedb"
ctx = snowflake.connector.connect(connection_string)

but got back error message:

TypeError                                 Traceback (most recent call last)
<ipython-input-19-ca89ef96ad7d> in <module>
----> 1 ctx = snowflake.connector.connect(connection_string)

TypeError: Connect() takes 0 positional arguments but 1 was given

I also tried extracting python dictionary from string with ast library and feeding it into snowflake.connector.connect(), but got back the same error.

So is there way to solve it? Am I missing something conceptually?

user1700890
  • 7,144
  • 18
  • 87
  • 183
  • 1
    If you know that **;**is a separator in your connection_string, can't you just split it by that separator and use each value of the list as one of the args in the connect method? – Sergiu Mar 09 '22 at 08:25

1 Answers1

1

Please check if given references can help:

Snowflake connector variables are separate .we may need to separate by split method. Conn=Connection_string.split(‘;’) and use it in snowflake connector. Note : For the ACCOUNT parameter, use your account identifier ,the account identifier does not include the snowflakecomputing.com domain name/ suffix. Snowflake automatically appends this when creating the connection.So it may work for snowflake connector.

So try giving connection variables first before and then use the variables in snowflake connector and connection string. Or
Try to include driver and server in the connection string by saving the complete connection string including accountname, username, password, database, warehouse details in Azure Key Vault .

Sample connection string format :

"jdbc:snowflake://<accountname>.snowflakecomputing.com/?user=<username>&db=<database>&warehouse=<warehouse>&role=<myRole>"

References:

  1. Configuring the JDBC Driver — Snowflake Documentation
  2. ODBC connection string to Snowflake for Access Pass Thru Query - Stack Overflow
  3. azure-docs/connector-snowflake.md at main · MicrosoftDocs/azure-docs · GitHub
  4. connect-snowflake-using-python-pyodbc-odbc-driver
kavyaS
  • 8,026
  • 1
  • 7
  • 19