I build up a connection to snowflake from python with snowpark session library using the authenticator externalbrowser. When I run the code then the browser opens and I type in my credentials. The python code is executing and I get the data from snowflake.
But this happens everytime when I run the python code. Is there a way to store authenticator information to use them multiple times?
I use the same authentication via externalbrowser with datagrip and I can use the authentication several hours.
from snowflake.snowpark import Session
connection_parameters = {
"account": "xyz",
"authenticator": "externalbrowser",
"user": "abcde",
"role": "role_one",
"warehouse": "tiny",
"database": "db1234"
}
# create session
session = Session.builder.configs(connection_parameters).create()
I build up a connection to snowflake from python with snowpark session library using the authenticator externalbrowser. When I run the code then the browser opens and I type in my credentials. The python code is executing and I get the data from snowflake.
But this happens everytime when I run the python code. Is there a way to store authenticator information to use them multiple times?
I use the same authentication via externalbrowser with datagrip and I can use the authentication several hours.
from snowflake.snowpark import Session
connection_parameters = {
"account": "xyz",
"authenticator": "externalbrowser",
"user": "abcde",
"role": "role_one",
"warehouse": "tiny",
"database": "db1234"
}
# create session
session = Session.builder.configs(connection_parameters).create()
Share
Improve this question
asked Nov 20, 2024 at 11:21
flubberflubber
32 bronze badges
2 Answers
Reset to default 0Yes, you can store authentication tokens using Snowflake's private key authentication instead of external browser. Here's how:
- Generate a private key pair:
openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt
openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub
- Add public key to Snowflake:
ALTER USER your_username SET RSA_PUBLIC_KEY='contents_of_rsa_key.pub';
- Update your Python code:
from snowflake.snowpark import Session
connection_parameters = {
"account": "xyz",
"user": "abcde",
"private_key_path": "path/to/rsa_key.p8",
"role": "role_one",
"warehouse": "tiny",
"database": "db1234"
}
session = Session.builder.configs(connection_parameters).create()
This eliminates the need for browser authentication on each run.
The solution is to install this package:
pip install "snowflake-connector-python[secure-local-storage]"
The token is stored in the background so that the browser window no longer opens.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742361985a4429570.html
评论列表(0条)