0

I'm working on a Snowpark project using the Python API. My Snowflake account requires SSO, so I've used the SSO method to get connected, but I'm having issues with there being no defined session. How do I fix this so that I can start working with this data?

My SSO code:

import snowflake.connector
import sys
con = snowflake.connector.connect(
    user=<"username">, 
    account=<account name">,
    authenticator="externalbrowser",
)
cur = con.cursor()
print(sys.executable)
print(sys.version)
print(sys.version_info)
try:
    cur.execute("select current_date")
    one_row=cur.fetchone()
    print("Current_Date:",one_row[0])
    cur.execute("SELECT current_version()")
    one_row = cur.fetchone()
    print("Snowfalke_Version:",one_row[0])
finally:
    cur.close()
cur.close()

First query run:

provider_table= session.table("ENVIRONMENT.<view name>")

And I get this error: NameError: name 'session' is not defined

I admit that I know that I don't define "session" prior to calling it -- I'm just not sure of the method to do so. Anyone know? Thanks!

Raphael Roth
  • 26,751
  • 15
  • 88
  • 145

1 Answers1

0

The session should be initialized and then used in the code as detailed here: https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-session.html#creating-a-session

Srinath Menon
  • 1,479
  • 8
  • 11
  • When I use that method, I get a Key Error with my account name. I just inserted it with "" I'm not sure if this is related to the fact that my account requires SSO. – drymolasses Aug 16 '22 at 15:38
  • Not sure if the code posted in the initial thread has typos but a sample Python code using Snowflake connector is here : https://docs.snowflake.com/en/user-guide/python-connector-install.html#step-2-verify-your-installation – Srinath Menon Aug 16 '22 at 17:08