Home > Blockchain >  Pulling Snowflake table into Dataframe
Pulling Snowflake table into Dataframe

Time:10-20

I continue to get and error "ProgrammingError: 002003 (42502): SQL compilation error: Object 'Table' does not exist or not authorized. I am using the following code:

con = snowflake.connector.connect(
user = "user.name",
authenticator="externalbrowser",
warehouse = "ware house name",
database = "db name",
schema = "schema name"
)
cur.con.cursor()
sql = "select * from Table"
cur.execute(sql)
df = cur.fetch_pandas_all()

When I execute the code in Jupyter Notebook the browser window opens and authenticates my creds but when it gets to the sql execute line the error rises and tells me that the table does not exist. When I open up Snowflake in my browser I can see that the table does exist in the correct warehouse, database and schema I have in my code.

Has anyone else ever experienced this? Do I need to authorize my user to be able to access this table via Python and Jupyter Notebook? Any help or suggestions on this would be great! Thanks in advance.

CodePudding user response:

It's likely your session doesn't have a role assigned to it (current role). You can add the role in your list of connection session paramters, e.g. add something like the following

role = 'RICH_ROLE',

You might want to consider setting a default role for your user.

ALTER USER userNameHere SET DEFAULT_ROLE = 'THE_BEST_ROLE';

docs link: https://docs.snowflake.com/en/sql-reference/sql/alter-user.html

Also, when all else fails, use the fully qualified table name, note this won't help much if the role isn't set:

sql = "select * from databaseName.schemaName.TableName"

I hope this helps...Rich

p.s. If this (or another) answer helps you, please take a moment to "accept" the answer that helped by clicking on the check mark beside the answer to toggle it from "greyed out" to "filled in".

  • Related