0
votes

I am using a private key authentication to connect to Snowflake using python, **This is working successfully when connecting directly using Java Client

import snowflake.connector
import os
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_key.p8", "rb") as key:
    p_key= serialization.load_pem_private_key(
        key.read(),
        password='XXXXX'.encode(),
        backend=default_backend()
    )

pkb = p_key.private_bytes(
    encoding=serialization.Encoding.DER,
    format=serialization.PrivateFormat.PKCS8,
    encryption_algorithm=serialization.NoEncryption())

conn = snowflake.connector.connect(
    user=XXXXX,
    password=XXXXXXX,
    account=XXXXXXXXX,
    private_key=pkb,
    warehouse=XXX,
    database=XXXXXX,
    schema=XXXX

    )

Have masked real values where needed, but these are correct as same as work direct with Java client.

Error:

/usr/lib/python3/dist-packages/jwt/algorithms.py:179: CryptographyDeprecationWarning: signer and verifier have been deprecated. Please use sign and verify instead.
  self.hash_alg()
Traceback (most recent call last):
  File "tryconnection.py", line 37, in <module>
    schema='PUBLIC'
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/__init__.py", line 53, in Connect
    return SnowflakeConnection(**kwargs)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/connection.py", line 189, in __init__
    self.connect(**kwargs)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/connection.py", line 493, in connect
    self.__open_connection()
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/connection.py", line 710, in __open_connection
    self.__authenticate(auth_instance)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/connection.py", line 963, in __authenticate
    session_parameters=self._session_parameters,
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/auth.py", line 217, in authenticate
    socket_timeout=self._rest._connection.login_timeout)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/network.py", line 530, in _post_request
    _include_retry_params=_include_retry_params)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/network.py", line 609, in fetch
    **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/network.py", line 711, in _request_exec_wrapper
    raise e
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/network.py", line 653, in _request_exec_wrapper
    method, full_url, headers, data, conn)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/network.py", line 758, in _handle_unknown_error
    u'errno': ER_FAILED_TO_REQUEST,
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/errors.py", line 100, in errorhandler_wrapper
    connection.errorhandler(connection, cursor, errorclass, errorvalue)
  File "/usr/local/lib/python3.6/dist-packages/snowflake/connector/errors.py", line 73, in default_errorhandler
    done_format_msg=errorvalue.get(u'done_format_msg'))
snowflake.connector.errors.OperationalError: 250003: None: Failed to get the response. Hanging? method: post, url: 

Thank you in advance for your help.

1
Its unable to reach the endpoint.Is it a private link endpoint ?Ankur Srivastava
Is this on the same machine? Is the issue intermittent? Might help to do a packet trace and see if there's any holdup.Suzy Lockwood

1 Answers

1
votes

I can not see the rest of the error message so I couldn't be sure. Are you sure enter your account name (and region and cloud if needed) as the account parameter, instead of full Snowflake URL?

https://docs.snowflake.com/en/user-guide/python-connector-example.html#connecting-to-snowflake

When connecting Jira, usually people uses JDBC connection string which includes full snowflake URL:

https://docs.snowflake.com/en/user-guide/python-connector-example.html#connecting-to-snowflake