I am trying to connect to snowflake using RSA but getting below error, I have tried with working code from online but still same error. I am not sure if I missed anything.
Error Message:
C:/Users/Prabhakar/AppData/Local/Programs/Python/Python312/python.exe d:/Snowflake/Learning/Python/VSO/Sample1.py
Traceback (most recent call last):
File “d:SnowflakeLearningPythonVSOSample1.py”, line 21, in <module>
password=os.environ[‘PRIVATE_KEY_PASSPHRASE’].encode(),
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File ” frozen os >”, line 714, in getitem
KeyError: ‘PRIVATE_KEY_PASSPHRASE’
import os
import logging
import snowflake.connector
for logger_name in ['snowflake.connector', 'botocore', 'boto3']:
logger = logging.getLogger(logger_name)
logger.setLevel(logging.DEBUG)
ch = logging.FileHandler('/ingest.log')
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s'))
logger.addHandler(ch)
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.asymmetric import dsa
from cryptography.hazmat.primitives import serialization
with open("RSA/rsa_key.p8", "rb") as key:
p_key= serialization.load_pem_private_key(
key.read(),
password=os.environ['PRIVATE_KEY_PASSPHRASE'].encode(),
backend=default_backend()
)
pkb = p_key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption())
ctx = snowflake.connector.connect(
private_key=pkb,
user='PRABHA',
account='ul72225',
warehouse='LEARNING',
database='PRABHADEV',
schema='DBO'
)
cs = ctx.cursor()
try:
cs.execute("SELECT current_version()")
one_row = cs.fetchone()
print(one_row[0])
finally:
cs.close()
ctx.close()
text
I followed all steps to configure RSA and everything is fine but python code is throwing error. Above code is someone else code which was working for them and even if I use same code it’s throwing same error
Prabha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1