Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1648412: Unable to connect to my warehouse inside snowpark container service #2042

Closed
punitchauhan771 opened this issue Sep 2, 2024 · 4 comments
Assignees
Labels
status-triage_done Initial triage done, will be further handled by the driver team

Comments

@punitchauhan771
Copy link

punitchauhan771 commented Sep 2, 2024

Hi,
I am trying to connect to my warehouse inside my spcs container but it is giving me this error:


Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 1414, in _authenticate
    auth.authenticate(
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/auth/_auth.py", line 250, in authenticate
    ret = self._rest._post_request(
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/network.py", line 739, in _post_request
    ret = self.fetch(
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/network.py", line 854, in fetch
    ret = self._request_exec_wrapper(
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/network.py", line 971, in _request_exec_wrapper
    raise e
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/network.py", line 896, in _request_exec_wrapper
    return_object = self._request_exec(
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/network.py", line 1156, in _request_exec
    raise err
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/network.py", line 1100, in _request_exec
    raise OperationalError(

The above exception (251012: 251012: Login request is retryable. Will be handled by authenticator) was the direct cause of the following exception:
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 263, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/django_snowflake/base.py", line 154, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/__init__.py", line 55, in Connect
    return SnowflakeConnection(**kwargs)
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 456, in __init__
    self.connect(**kwargs)
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 771, in connect
    self.__open_connection()
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 1099, in __open_connection
    self.authenticate_with_retry(self.auth_class)
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 1386, in authenticate_with_retry
    self._authenticate(auth_instance)
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 1458, in _authenticate
    raise auth_op from e
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/connection.py", line 1435, in _authenticate
    auth_instance.handle_timeout(
  File "/usr/local/lib/python3.11/site-packages/snowflake/connector/auth/by_plugin.py", line 212, in handle_timeout
    raise error

@github-actions github-actions bot changed the title Unable to connect to my warehouse inside snowpark container service SNOW-1648412: Unable to connect to my warehouse inside snowpark container service Sep 2, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Sep 3, 2024
@sfc-gh-dszmolka sfc-gh-dszmolka added status-information_needed Additional information is required from the reporter status-triage Issue is under initial triage labels Sep 3, 2024
@sfc-gh-dszmolka
Copy link
Contributor

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

  1. enable debug level logging and try to connect again
  2. collect the logs, sanitize it to make sure no personal information is in it, and share for analysis ?

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.

@punitchauhan771
Copy link
Author

punitchauhan771 commented Sep 4, 2024

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:
image

and my local environment logs:
image

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.

@punitchauhan771
Copy link
Author

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.

@sfc-gh-dszmolka
Copy link
Contributor

no problem at all, glad to hear you discovered this typo and are now unblocked 👍

@sfc-gh-dszmolka sfc-gh-dszmolka added status-triage_done Initial triage done, will be further handled by the driver team and removed status-information_needed Additional information is required from the reporter status-triage Issue is under initial triage labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

2 participants