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) 
'''
1
  • Can you try any other command like "Select current_date;" Commented May 28, 2020 at 12:29

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.