Closed punitchauhan771 closed 2 months ago
hello - unfortunately the actual issue is not included in the log snippet you shared. It might be even due to a simple misconfiguration (incorrect account name/format used, etc) or something else.
Could you please
I also recommend perhaps giving https://github.com/Snowflake-Labs/sf-samples/tree/main/samples/spcs/sf-connection/python a quick look; it should demonstrate how to connect with PythonConnector in SPCS, perhaps it gives some idea for the implementation.
Hi, Thank you for your suggestions, after enabling logging, I tried to connect to snowflake warehouse both in my local environment and spcs, logs for each of them are below: SPCS logs:
and my local environment logs:
In my local environment I am able to connect to my snowflake db but in spcs it's failing to connect, also I haven't cleaned any logs in SPCS, only this much log was generated,
this is the code that I am using to connect (db config)
import snowflake.connector as Database
def get_connection_params(self):
settings_dict = self.settings_dict
conn_params = {
'interpolate_empty_sequences': True,
**settings_dict['OPTIONS'],
}
if os.environ.get('RUNNING_DJANGOS_TEST_SUITE') != 'true':
conn_params['application'] = 'Django_SnowflakeConnector_%s' % __version__
if use_token := os.path.exists("/snowflake/session/token"):
conn_params["token"] = self.get_login_token()
if settings_dict['NAME']:
conn_params['database'] = settings_dict['NAME']
# Omit USER/PASSWORD if using token.
if not use_token:
if settings_dict['USER']:
conn_params['user'] = settings_dict['USER']
else:
raise ImproperlyConfigured(self.settings_is_missing % 'USER')
if settings_dict['PASSWORD']:
conn_params['password'] = settings_dict['PASSWORD']
elif 'authenticator' not in conn_params:
raise ImproperlyConfigured(self.settings_is_missing % 'PASSWORD')
if settings_dict.get('ACCOUNT'):
conn_params['account'] = settings_dict['ACCOUNT']
else:
raise ImproperlyConfigured(self.settings_is_missing % 'ACCOUNT')
if settings_dict.get('WAREHOUSE'):
conn_params['warehouse'] = settings_dict['WAREHOUSE']
else:
raise ImproperlyConfigured(self.settings_is_missing % 'WAREHOUSE')
if settings_dict.get('SCHEMA'):
conn_params['schema'] = settings_dict['SCHEMA']
else:
raise ImproperlyConfigured(self.settings_is_missing % 'SCHEMA')
return conn_params
@async_unsafe
def get_new_connection(self, conn_params):
try:
Database.connect(**conn_params)
except Exception as e:
print(conn_params)
print(e)
raise Exception(e)
##SPCS connectivity
DATABASES = {
'default': {
'ENGINE': '**',
'ACCOUNT': os.getenv("SNOWFLAKE_ACCOUNT"),
'SCHEMA': 'DBO',
'WAREHOUSE':os.getenv("SNOWFLAKE_WAREHOUSE","RANDOM_WAREHOUSE_NAME"),
'NAME': os.getenv("SNOWFLAKE_DATABASE"),
'PORT': '',
'CONN_MAX_AGE': None,
'HOST' : os.getenv('SNOWFLAKE_HOST'),
'OPTIONS': {
"token" : open('/snowflake/session/token', 'r').read(),
"authenticator" : "oauth",
'client_session_keep_alive': True,
'protocol': "https"
},
},
}
##Local Env Connectivity
DATABASES = {
'default': {
'ENGINE': '**',
'ACCOUNT': '<AccountName>',
'SCHEMA': 'DBO',
'WAREHOUSE': str(config['APP']['warehouse']),
'USER': str(config['APP']['username']),
'PASSWORD': str(config['APP']['password']),
'NAME': str(config['APP']['database_name']),
'PORT': '',
'CONN_MAX_AGE': None,
'HOST': str(config['APP']['server']),
'OPTIONS': {
"role" : "ACCOUNTADMIN",
'client_session_keep_alive': True
},
},
}
additional error that I see is :
It's trying to connect to: "HTTPSConnectionPool(host='<url>.snowflakecomputing.com', port=443)"
The connection attempts are timing out: "251011: 251011: ConnectionTimeout occurred during login."
This suggests that either the Snowflake host is unreachable from your application's environment, or there might be network restrictions preventing the connection. Since Its inside SPCS , I don't have to specify any egress config right ?, also If i specify egress config then it throws me the above error.
Hi,
After further debugging, I discovered that the issue was due to a typo in my code, which caused the hostname to be skipped during the connection process. I’ve corrected the mistake. Apologies for any inconvenience this may have caused.
no problem at all, glad to hear you discovered this typo and are now unblocked 👍
Hi, I am trying to connect to my warehouse inside my spcs container but it is giving me this error: