0

I tried to connect snowflake(SSO Authentication) and get data from table. But, When i run the code, i can login with my credentials in the pop-up browser window and it connect Snowflake, no response after that(the program neither terminate nor provide result). Not sure, where am doing mistake, Pls help.

'''

import snowflake.connector
# Connecting to Snowflake using SAML 2.0-compliant IdP federated authentication
conn = snowflake.connector.connect(
  user='G*****K',
  account='abcdf',
  authenticator='externalbrowser',
  warehouse='abcdf',
  database='abcdf',
  schema='abcdf'
)
cur = conn.cursor()
sql = "select * from abcdf.ACCT limit 10"
x=cur.execute(sql)
cur.close()
print(x) 
'''
Guruprakash
  • 13
  • 1
  • 5

2 Answers2

1

I believe you are closing the cursor before the print;

    try:
    cur.execute("SELECT col1, col2 FROM test_table ORDER BY col1")
    for (col1, col2) in cur:
        print('{0}, {1}'.format(col1, col2))
    finally:
    cur.close() 

Details: https://docs.snowflake.com/en/user-guide/python-connector-example.html#using-cursor-to-fetch-values

FKayani
  • 981
  • 1
  • 5
  • 10
0

Results of the query are stored in cursor. The contents of cursor may then be stored in a local variable.

Also, best practice to close connection in the end.

https://www.psycopg.org/docs/cursor.html

import snowflake.connector
# Connecting to Snowflake using SAML 2.0-compliant IdP federated authentication
conn = snowflake.connector.connect(
  user='G*****K',
  account='abcdf',
  authenticator='externalbrowser',
  warehouse='abcdf',
  database='abcdf',
  schema='abcdf'
)
cur = conn.cursor()
sql = "select * from abcdf.ACCT limit 10"
cur.execute(sql)
print(cur.fetchall())
cur.close()
conn.close()