snowflakedb / snowflake-connector-python

Snowflake Connector for Python
https://pypi.python.org/pypi/snowflake-connector-python/
Apache License 2.0
586 stars 468 forks source link

OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb' #166

Closed larissalong closed 5 years ago

larissalong commented 5 years ago

I would like to connect to Snowflake via Python connector in Anaconda Spyder.

What I did was to: 1) install snowflake in Anaconda Prompt using 'pip install snowflake-connector-python' 2) then run code 'import snowflake.connector' in Spyder.

import snowflake.connector

There should not be any error shown after I imported the snowflake.connector in Spyder.

However, what I saw instead was shown below:

Traceback (most recent call last):

  File "<ipython-input-12-7f0d85f84b83>", line 1, in <module>
    import snowflake.connector # ??

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\__init__.py", line 21, in <module>
    from .connection import SnowflakeConnection

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\connection.py", line 40, in <module>
    from .cursor import SnowflakeCursor

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\cursor.py", line 29, in <module>
    from .file_transfer_agent import (SnowflakeFileTransferAgent)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\file_transfer_agent.py", line 20, in <module>
    from .azure_util import SnowflakeAzureUtil

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\azure_util.py", line 14, in <module>
    from .encryption_util import (EncryptionMetadata)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\encryption_util.py", line 12, in <module>
    from Cryptodome.Cipher import AES

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\Cryptodome\Cipher\__init__.py", line 27, in <module>
    from Cryptodome.Cipher._mode_ecb import _create_ecb_cipher

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\Cryptodome\Cipher\_mode_ecb.py", line 47, in <module>
    """

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\Cryptodome\Util\_raw_api.py", line 300, in load_pycryptodome_raw_lib
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))

OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb': Trying '_raw_ecb.cp36-win_amd64.pyd': cannot load library 'C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\Cryptodome\Util\..\Cipher\_raw_ecb.cp36-win_amd64.pyd': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\Users\\338905\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Cryptodome\\Util\\..\\Cipher\\_raw_ecb.cp36-win_amd64.pyd', Trying '_raw_ecb.pyd': cannot load library 'C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\Cryptodome\Util\..\Cipher\_raw_ecb.pyd': error 0x7e.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'C:\\Users\\338905\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\Cryptodome\\Util\\..\\Cipher\\_raw_ecb.pyd'

After I collect the logs by running the below code, It returned 'botocore'.

import logging
import os

for logger_name in ['snowflake.sqlalchemy', 'snowflake.connector', 'botocore']: 
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    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)

My info:

  1. What version of Python are you using (python --version)?

    Python - 3.6.7
    Spyder - 3.3.1
    Anaconda Navigator 1.9.7
  2. What operating system and processor architecture are you using (python -c 'import platform; print(platform.platform())')?

    Windows-10-10.0.17763-SP0
  3. What are the component versions in the environment (pip list)?

    alabaster                          0.7.12             
    altgraph                           0.16.1             
    anaconda-client                    1.7.2              
    anaconda-navigator                 1.9.7              
    anaconda-project                   0.8.2              
    asn1crypto                         0.24.0             
    astroid                            2.2.5              
    astropy                            3.1.2              
    atomicwrites                       1.3.0              
    attrs                              19.1.0             
    azure-common                       1.1.18             
    azure-storage-blob                 1.5.0              
    azure-storage-common               1.4.0              
    Babel                              2.6.0              
    backcall                           0.1.0              
    backports.os                       0.1.1              
    backports.shutil-get-terminal-size 1.0.0              
    beautifulsoup4                     4.7.1              
    bitarray                           0.8.3              
    bkcharts                           0.2                
    blaze                              0.11.3             
    bleach                             3.1.0              
    blinker                            1.4                
    bokeh                              1.0.4              
    boto                               2.49.0             
    boto3                              1.9.130            
    botocore                           1.12.130           
    Bottleneck                         1.2.1              
    bz2file                            0.98               
    certifi                            2019.3.9           
    cffi                               1.12.2             
    chardet                            3.0.4              
    Click                              7.0                
    cloudpickle                        0.8.1              
    clyent                             1.2.2              
    colorama                           0.4.1              
    comtypes                           1.1.7              
    conda                              4.6.11             
    conda-build                        3.17.8             
    conda-verify                       3.1.1              
    contextlib2                        0.5.5              
    convertdate                        2.1.3              
    crypto                             1.4.1              
    cryptography                       2.6.1              
    cycler                             0.10.0             
    Cython                             0.29.6             
    cytoolz                            0.9.0.1            
    dask                               1.1.5              
    datashape                          0.5.4              
    decorator                          4.4.0              
    defusedxml                         0.5.0              
    distributed                        1.26.1             
    docutils                           0.14               
    entrypoints                        0.3                
    ephem                              3.7.6.0            
    et-xmlfile                         1.0.1              
    fastcache                          1.0.2              
    fbprophet                          0.4.post2          
    filelock                           3.0.10             
    Flask                              1.0.2              
    Flask-Cors                         3.0.7              
    future                             0.17.1             
    gensim                             3.5.0              
    gevent                             1.3.7              
    glob2                              0.6                
    greenlet                           0.4.13             
    h5py                               2.8.0              
    heapdict                           1.0.0              
    holidays                           0.9.10             
    html5lib                           1.0.1              
    idna                               2.8                
    ijson                              2.3                
    imageio                            2.5.0              
    imagesize                          1.1.0              
    importlib-metadata                 0.0.0              
    ipykernel                          5.1.0              
    ipython                            7.4.0              
    ipython-genutils                   0.2.0              
    ipywidgets                         7.4.2              
    isort                              4.3.17             
    itsdangerous                       1.1.0              
    jdcal                              1.4                
    jedi                               0.13.3             
    Jinja2                             2.10.1             
    jmespath                           0.9.4              
    jsonschema                         3.0.1              
    jupyter-client                     5.2.4              
    jupyter-console                    6.0.0              
    jupyter-core                       4.4.0              
    jupyterlab                         0.35.4             
    jupyterlab-server                  0.2.0              
    keyring                            19.0.1             
    kiwisolver                         1.0.1              
    lazy-object-proxy                  1.3.1              
    libarchive-c                       2.8                
    llvmlite                           0.28.0             
    locket                             0.2.0              
    lunardate                          0.2.0              
    lxml                               4.3.3              
    macholib                           1.11               
    MarkupSafe                         1.1.1              
    matplotlib                         3.0.3              
    mccabe                             0.6.1              
    menuinst                           1.4.16             
    mistune                            0.8.4              
    mkl-fft                            1.0.11             
    mkl-random                         1.0.2              
    more-itertools                     4.3.0              
    mpmath                             1.1.0              
    msgpack                            0.6.1              
    multipledispatch                   0.6.0              
    Naked                              0.1.31             
    navigator-updater                  0.2.1              
    nbconvert                          5.4.1              
    nbformat                           4.4.0              
    networkx                           2.2                
    nltk                               3.2.5              
    nose                               1.3.7              
    notebook                           5.7.8              
    numba                              0.43.1             
    numexpr                            2.6.9              
    numpy                              1.16.2             
    numpydoc                           0.8.0              
    oauthlib                           3.0.1              
    odo                                0.5.1              
    olefile                            0.46               
    openpyxl                           2.6.1              
    packaging                          19.0               
    pandas                             0.24.2             
    pandocfilters                      1.4.2              
    parso                              0.4.0              
    partd                              0.3.9              
    path.py                            11.5.0             
    pathlib2                           2.3.3              
    patsy                              0.5.1              
    pefile                             2018.8.8           
    pep8                               1.7.1              
    pickleshare                        0.7.5              
    Pillow                             5.4.1              
    pip                                19.0.3             
    pkginfo                            1.5.0.1            
    pluggy                             0.9.0              
    ply                                3.11               
    prometheus-client                  0.6.0              
    prompt-toolkit                     2.0.9              
    psutil                             5.6.1              
    pubnub                             4.1.3              
    py                                 1.8.0              
    pycodestyle                        2.5.0              
    pycosat                            0.6.3              
    pycparser                          2.19               
    pycrypto                           2.6.1              
    pycryptodome                       3.8.1              
    pycryptodomex                      3.8.1              
    pycurl                             7.43.0.2           
    pyflakes                           2.1.1              
    Pygments                           2.3.1              
    PyInstaller                        3.3.dev0+dd2522afbc
    PyJWT                              1.7.1              
    pylint                             2.3.1              
    pyodbc                             4.0.26             
    pyOpenSSL                          19.0.0             
    pyparsing                          2.4.0              
    pyreadline                         2.1                
    pyrsistent                         0.14.11            
    PySocks                            1.6.8              
    pystan                             2.17.1.0           
    pytest                             4.4.0              
    pytest-arraydiff                   0.3                
    pytest-astropy                     0.5.0              
    pytest-doctestplus                 0.3.0              
    pytest-openfiles                   0.3.1              
    pytest-remotedata                  0.3.1              
    python-crfsuite                    0.9.6              
    python-dateutil                    2.8.0              
    pytz                               2018.9             
    PyWavelets                         1.0.2              
    pywin32                            224                
    pywin32-ctypes                     0.2.0              
    pywinpty                           0.5.5              
    PyYAML                             5.1                
    pyzmq                              18.0.1             
    QtAwesome                          0.5.7              
    qtconsole                          4.4.3              
    QtPy                               1.7.0              
    requests                           2.21.0             
    requests-oauthlib                  1.2.0              
    rope                               0.10.7             
    ruamel-yaml                        0.15.71            
    s3transfer                         0.2.0              
    scikit-image                       0.15.0             
    scikit-learn                       0.20.3             
    scipy                              1.2.1              
    seaborn                            0.9.0              
    Send2Trash                         1.5.0              
    setuptools                         41.0.0             
    shellescape                        3.4.1              
    simplegeneric                      0.8.1              
    singledispatch                     3.4.0.3            
    six                                1.12.0             
    smart-open                         1.8.0              
    snowballstemmer                    1.2.1              
    snowflake-connector-python         1.7.10             
    sortedcollections                  1.1.2              
    sortedcontainers                   2.1.0              
    soupsieve                          1.9                
    Sphinx                             2.0.1              
    sphinxcontrib-applehelp            1.0.1              
    sphinxcontrib-devhelp              1.0.1              
    sphinxcontrib-htmlhelp             1.0.1              
    sphinxcontrib-jsmath               1.0.1              
    sphinxcontrib-qthelp               1.0.2              
    sphinxcontrib-serializinghtml      1.1.1              
    sphinxcontrib-websupport           1.1.0              
    spyder                             3.3.1              
    spyder-kernels                     0.4.4              
    SQLAlchemy                         1.3.2              
    statsmodels                        0.9.0              
    sympy                              1.3                
    tables                             3.4.4              
    tblib                              1.3.2              
    terminado                          0.8.2              
    testpath                           0.4.2              
    toolz                              0.9.0              
    tornado                            6.0.2              
    tqdm                               4.31.1             
    traitlets                          4.3.2              
    twython                            3.7.0              
    typed-ast                          1.3.1              
    unicodecsv                         0.14.1             
    urllib3                            1.24.1             
    wcwidth                            0.1.7              
    webencodings                       0.5.1              
    Werkzeug                           0.15.2             
    wheel                              0.33.1             
    widgetsnbextension                 3.4.2              
    win-inet-pton                      1.1.0              
    win-unicode-console                0.5                
    wincertstore                       0.2                
    wrapt                              1.11.1             
    xlrd                               1.2.0              
    XlsxWriter                         1.1.6              
    xlwings                            0.15.5             
    xlwt                               1.3.0              
    zict                               0.1.4        
    zipp                              0.3.3
smtakeda commented 5 years ago

Try

pip install -U --force-reinstall pycryptodomex

Looks like your PyCryptodome is corrupted.

larissalong commented 5 years ago

Try pip install -U --force-reinstall pycryptodomex

Looks like your PyCryptodome is corrupted.

Thanks Shige. After following the step above, I managed to import snowflake in Spyder. However, a new error appeared when I run the below code:

import snowflake.connector
# Gets the version
ctx = snowflake.connector.connect(
    user='username',
    password='pwd',
    account='myaccount'
    )
cs = ctx.cursor()
try:
    cs.execute("SELECT current_version()")
    one_row = cs.fetchone()
    print(one_row[0])
finally:
    cs.close()
ctx.close()

This is the error message, can you advise how to fix this:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\network.py", line 648, in _request_exec_wrapper
    **kwargs)
  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\network.py", line 865, in _request_exec
    raise RetryRequest(err)
snowflake.connector.network.RetryRequest: module 'Cryptodome' has no attribute 'Util'
2019-04-16 09:14:13,412 - MainThread network.py:905 - _use_requests_session() - DEBUG - Active requests sessions: 0, idle: 1
Traceback (most recent call last):

  File "<ipython-input-17-641e71603e0c>", line 4, in <module>
    account='petco.us-east-1'

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\__init__.py", line 33, in Connect
    return SnowflakeConnection(**kwargs)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\connection.py", line 175, in __init__
    self.connect(**kwargs)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\connection.py", line 439, in connect
    self.__open_connection()

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\connection.py", line 653, in __open_connection
    self.__authenticate(auth_instance)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\connection.py", line 877, in __authenticate
    session_parameters=self._session_parameters,

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\auth.py", line 225, in authenticate
    socket_timeout=self._rest._connection.login_timeout)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\network.py", line 530, in _post_request
    _include_retry_params=_include_retry_params)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\network.py", line 608, in fetch
    **kwargs)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\network.py", line 666, in _request_exec_wrapper
    conn, full_url, cause)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\network.py", line 696, in handle_invalid_certificate_error
    u'errno': ER_FAILED_TO_REQUEST,

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\errors.py", line 100, in errorhandler_wrapper
    connection.errorhandler(connection, cursor, errorclass, errorvalue)

  File "C:\Users\338905\AppData\Local\Continuum\anaconda3\lib\site-packages\snowflake\connector\errors.py", line 73, in default_errorhandler
    done_format_msg=errorvalue.get(u'done_format_msg'))

OperationalError: 250003: None: Failed to execute request: module 'Cryptodome' has no attribute 'Util'
larissalong commented 5 years ago

My code works after I restarted my laptop. Thank you Shige for the help!