unable to connect to snowflake

扶醉桌前 提交于 2019-12-24 13:44:58

问题


I am trying to connect to snowflake from python. It's very simple straight forward, but unfortunately I'm unable to succeed. Same piece of code works in other machines (when my friends tested). Not sure what dependencies I'm missing. Tried debugging very hard, even tried with pipenv (assuming python path must be conflict) but no luck. I kindly request you to help and resolve this issue. Summarising below steps what i have done.

sudo -H pip install pipenv    #installed pipenv

mkdir -p test_vn    #Created a directory

cd test_vn/

pipenv install requests     #Installed requests module

Since, it's a virtual , i checked the path where packages are installed.

/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages

-rw-r--r--   1 james  staff   126 Nov  1 09:24 easy_install.py
-rw-r--r--   1 james  staff   367 Nov  1 09:24 easy_install.pyc
drwxr-xr-x  11 james  staff   374 Nov  1 09:24 setuptools-40.5.0.dist-info
drwxr-xr-x  69 james  staff  2346 Nov  1 09:24 setuptools
drwxr-xr-x   8 james  staff   272 Nov  1 09:24 pkg_resources
drwxr-xr-x   8 james  staff   272 Nov  1 09:24 pip
drwxr-xr-x   9 james  staff   306 Nov  1 09:24 wheel-0.32.2.dist-info
drwxr-xr-x  19 james  staff   646 Nov  1 09:24 wheel
drwxr-xr-x   9 james  staff   306 Nov  1 09:24 pip-18.1.dist-info
drwxr-xr-x   8 james  staff   272 Nov  1 09:24 idna-2.7.dist-info
drwxr-xr-x  18 james  staff   612 Nov  1 09:24 idna
drwxr-xr-x   8 james  staff   272 Nov  1 09:24 urllib3-1.24.dist-info
drwxr-xr-x  25 james  staff   850 Nov  1 09:24 urllib3
drwxr-xr-x  10 james  staff   340 Nov  1 09:24 requests-2.20.0.dist-info
drwxr-xr-x  38 james  staff  1292 Nov  1 09:24 requests
drwxr-xr-x  10 james  staff   340 Nov  1 09:24 chardet-3.0.4.dist-info
drwxr-xr-x  81 james  staff  2754 Nov  1 09:24 chardet
drwxr-xr-x  10 james  staff   340 Nov  1 09:24 certifi-2018.10.15.dist-info
drwxr-xr-x   9 james  staff   306 Nov  1 09:24 certifi

now, installing pyOpenSSL and snowflake-connector as mentioned below

pipenv install pyOpenSSL       #Installed pyOpenSSL
pipenv install snowflake-connector-python     #Installed snowflake-connector

Now /Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages has below site-packages1

created a file test.py under /Users/james/test_vn

import os
print os.__file__
import snowflake.connector
import logging
logging.basicConfig(
    filename='snowflake_python_connector.log',
    level=logging.DEBUG)

# Gets the version
ctx = snowflake.connector.connect(
    user='user-name',
    password='pass-word',
    account='test_account'
    )
cs = ctx.cursor()
try:
    cs.execute("SELECT current_version()")
    one_row = cs.fetchone()
    print(one_row[0])
finally:
    cs.close()
ctx.close()

when i execute the script, (test_vn) bash-3.2$ pipenv run python test.py

/Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/requirementslib/models/utils.py:19: UserWarning: Module pathlib2 was already imported from /Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/pathlib2/__init__.pyc, but /usr/local/lib/python2.7/site-packages/pathlib2-2.3.2-py2.7.egg is being added to sys.path
  from pkg_resources import Requirement
/Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/requirementslib/models/utils.py:19: UserWarning: Module attr was already imported from /Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/attr/__init__.pyc, but /usr/local/lib/python2.7/site-packages/attrs-18.2.0-py2.7.egg is being added to sys.path
  from pkg_resources import Requirement
/Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/requirementslib/models/utils.py:19: UserWarning: Module scandir was already imported from /Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/scandir.pyc, but /usr/local/lib/python2.7/site-packages/scandir-1.9.0-py2.7-macosx-10.12-x86_64.egg is being added to sys.path
  from pkg_resources import Requirement
/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/os.py
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    account='test_account'
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/__init__.py", line 32, in Connect
    return SnowflakeConnection(**kwargs)
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/connection.py", line 157, in __init__
    self.connect(**kwargs)
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/connection.py", line 397, in connect
    self.__open_connection()
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/connection.py", line 595, in __open_connection
    self.__authenticate(auth_instance)
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/connection.py", line 818, in __authenticate
    session_parameters=self._session_parameters,
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/auth.py", line 214, in authenticate
    socket_timeout=self._rest._connection.login_timeout)
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/network.py", line 538, in _post_request
    _include_retry_params=_include_retry_params)
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/network.py", line 627, in fetch
    **kwargs)
  File "/Users/james/.local/share/virtualenvs/test_vn-mReMX2sP/lib/python2.7/site-packages/snowflake/connector/network.py", line 704, in _request_exec_wrapper
    raise e
ImportError: cannot import name dump_publickey
(test_vn) bash-3.2$ 

snowflake_python_connector.log

INFO:snowflake.connector.connection:Snowflake Connector for Python Version: 1.6.12, Python Version: 2.7.14, Platform: Darwin-16.7.0-x86_64-i386-64bit
DEBUG:snowflake.connector.connection:connect
DEBUG:snowflake.connector.connection:__config
DEBUG:snowflake.connector.converter:use_sfbinaryformat: False, use_numpy: False
DEBUG:snowflake.connector.connection:REST API object was created: test_account.snowflakecomputing.com:443, proxy=None:None, proxy_user=None
DEBUG:snowflake.connector.auth:authenticate
DEBUG:snowflake.connector.auth:assertion content: *********
DEBUG:snowflake.connector.auth:account=test_account, user=user-name, database=None, schema=None, warehouse=None, role=None, request_id=b085d6f3-42fc-40c1-b28a-5c78f36e1a88
DEBUG:snowflake.connector.auth:body['data']: {u'CLIENT_APP_VERSION': u'1.6.12', u'CLIENT_APP_ID': u'PythonConnector', u'CLIENT_ENVIRONMENT': {u'PYTHON_VERSION': u'2.7.14', u'APPLICATION': u'PythonConnector', u'OS_VERSION': 'Darwin-16.7.0-x86_64-i386-64bit', u'PYTHON_COMPILER': 'GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)', u'OS': 'Darwin', u'PYTHON_RUNTIME': 'CPython'}, u'SESSION_PARAMETERS': {u'CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY': 900}, u'LOGIN_NAME': 'user-name', u'SVN_REVISION': None, u'ACCOUNT_NAME': 'test_account'}
DEBUG:botocore.vendored.requests.packages.urllib3.util.retry:Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None)
DEBUG:botocore.vendored.requests.packages.urllib3.util.retry:Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None)
DEBUG:snowflake.connector.network:Active requests sessions: 1, idle: 0
DEBUG:snowflake.connector.network:remaining request timeout: 120, retry cnt: 1
DEBUG:snowflake.connector.network:socket timeout: 60
INFO:botocore.vendored.requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): test_account.snowflakecomputing.com
DEBUG:snowflake.connector.network:Active requests sessions: 0, idle: 1

Not sure what's wrong here. Any path conflicts or any missing package dependencies ? Please help me.

https://docs.snowflake.net/manuals/user-guide/python-connector-install.html#step-1-install-the-connector

/Users/james/test_vn

pipenv run pip freeze

/Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/requirementslib/models/utils.py:19: UserWarning: Module pathlib2 was already imported from /Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/pathlib2/__init__.pyc, but /usr/local/lib/python2.7/site-packages/pathlib2-2.3.2-py2.7.egg is being added to sys.path
  from pkg_resources import Requirement
/Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/requirementslib/models/utils.py:19: UserWarning: Module attr was already imported from /Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/attr/__init__.pyc, but /usr/local/lib/python2.7/site-packages/attrs-18.2.0-py2.7.egg is being added to sys.path
  from pkg_resources import Requirement
/Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/requirementslib/models/utils.py:19: UserWarning: Module scandir was already imported from /Users/james/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/scandir.pyc, but /usr/local/lib/python2.7/site-packages/scandir-1.9.0-py2.7-macosx-10.12-x86_64.egg is being added to sys.path
  from pkg_resources import Requirement
altgraph==0.10.2
asn1crypto==0.24.0
azure-common==1.1.16
azure-nspkg==2.0.0
azure-storage==0.36.0
bdist-mpkg==0.5.0
bonjour-py==0.3
boto3==1.9.35
botocore==1.12.35
certifi==2018.10.15
cffi==1.11.5
chardet==3.0.4
cryptography==2.3.1
docutils==0.14
enum34==1.1.6
future==0.17.1
futures==3.2.0
idna==2.7
ijson==2.3
ipaddress==1.0.22
jmespath==0.9.3
macholib==1.5.1
matplotlib==1.3.1
modulegraph==0.10.4
numpy==1.8.0rc1
py2app==0.7.3
pyasn1==0.4.4
pyasn1-modules==0.2.2
pycparser==2.19
pycryptodomex==3.7.0
PyJWT==1.6.4
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
requests==2.20.0
s3transfer==0.1.13
scipy==0.13.0b1
six==1.4.1
snowflake-connector-python==1.6.12
urllib3==1.24
xattr==0.6.4
zope.interface==4.1.1

And also Versions above (pipenv run pip freeze) and in site-packages don't match.


回答1:


Try updating your PyOpenssl to latest - 18.0.0. For version requirements you can refer this page




回答2:


The best way to connect to snowflakes from Jupyter - https://github.com/sat28/jupyter-snowflakes

A simple python package that adds the snowflakes connection capability as an IPython cell magic.



来源:https://stackoverflow.com/questions/53095452/unable-to-connect-to-snowflake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!