snowflakedb / snowflake-connector-python

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

SNOW-1831724: AttributeError: module 'lib' has no attribute 'X509_V_FLAG_NOTIFY_POLICY' error on import with PyOpenSSL<22.1.0 installed #2109

Open gibsondan opened 3 days ago

gibsondan commented 3 days ago

Python version

3.11.7

Operating system and processor architecture

macOS-14.3.1-arm64-arm-64bit

Installed packages

+ agate==1.9.1
 + aiofile==3.9.0
 + alembic==1.14.0
 + annotated-types==0.7.0
 + antlr4-python3-runtime==4.13.2
 + anyio==4.6.2.post1
 + asn1crypto==1.5.1
 + assets-smoke-test==0.0.0 (from file:///Users/dgibson/dagster/examples/assets_smoke_test)
 + attrs==24.2.0
 + babel==2.16.0
 + backoff==2.2.1
 + backports-tarfile==1.2.0
 + buildkite-test-collector==0.1.9
 + cachetools==5.5.0
 + caio==0.9.17
 + certifi==2024.8.30
 + cffi==1.17.1
 + chardet==5.2.0
 + charset-normalizer==3.4.0
 + click==8.1.7
 + colorama==0.4.6
 + coloredlogs==14.0
 + coverage==7.6.8
 + croniter==3.0.4
 + cryptography==44.0.0
 + daff==1.3.46
 + dagster==1!0+dev (from file:///Users/dgibson/dagster/python_modules/dagster)
 + dagster-dbt==1!0+dev (from file:///Users/dgibson/dagster/python_modules/libraries/dagster-dbt)
 + dagster-graphql==1!0+dev (from file:///Users/dgibson/dagster/python_modules/dagster-graphql)
 + dagster-pandas==1!0+dev (from file:///Users/dgibson/dagster/python_modules/libraries/dagster-pandas)
 + dagster-pipes==1!0+dev (from file:///Users/dgibson/dagster/python_modules/dagster-pipes)
 + dagster-snowflake==1!0+dev (from file:///Users/dgibson/dagster/python_modules/libraries/dagster-snowflake)
 + dagster-snowflake-pandas==1!0+dev (from file:///Users/dgibson/dagster/python_modules/libraries/dagster-snowflake-pandas)
 + dagster-webserver==1!0+dev (from file:///Users/dgibson/dagster/python_modules/dagster-webserver)
 + dbt-adapters==1.7.0
 + dbt-common==1.10.0
 + dbt-core==1.8.8
 + dbt-extractor==0.5.1
 + dbt-semantic-interfaces==0.5.1
 + dbt-snowflake==1.8.4
 + deepdiff==7.0.1
 + distlib==0.3.9
 + docker==7.1.0
 + docstring-parser==0.16
 + execnet==2.1.1
 + filelock==3.16.1
 + flaky==3.8.1
 + fsspec==2024.3.0
 + gql==3.5.0
 + graphene==3.4.3
 + graphql-core==3.2.5
 + graphql-relay==3.2.0
 + grpcio==1.68.0
 + grpcio-health-checking==1.62.3
 + grpcio-tools==1.62.3
 + h11==0.14.0
 + httptools==0.6.4
 + humanfriendly==10.0
 + idna==3.10
 + importlib-metadata==6.11.0
 + iniconfig==2.0.0
 + isodate==0.6.1
 + jaraco-classes==3.4.0
 + jaraco-context==6.0.1
 + jaraco-functools==4.1.0
 + jinja2==3.1.4
 + jsonschema==4.23.0
 + jsonschema-specifications==2024.10.1
 + keyring==25.5.0
 + leather==0.4.0
 + logbook==1.5.3
 + mako==1.3.6
 + markdown-it-py==3.0.0
 + markupsafe==3.0.2
 + mashumaro==3.15
 + mdurl==0.1.2
 + minimal-snowplow-tracker==0.0.2
 + more-itertools==10.5.0
 + morefs==0.2.2
 + msgpack==1.1.0
 + multidict==6.1.0
 + mypy-protobuf==3.6.0
 + networkx==3.4.2
 + numpy==2.1.3
 + objgraph==3.6.2
 + ordered-set==4.1.0
 + orjson==3.10.12
 + packaging==24.2
 + pandas==2.2.3
 + parsedatetime==2.6
 + pathspec==0.12.1
 + platformdirs==4.3.6
 + pluggy==1.5.0
 + propcache==0.2.0
 + protobuf==4.25.5
 + pyarrow==18.1.0
 + pycparser==2.22
 + pydantic==2.9.2
 + pydantic-core==2.23.4
 + pygments==2.18.0
 + pyjwt==2.10.0
 + pyopenssl==22.0.0
 + pyproject-api==1.8.0
 + pytest==8.3.3
 + pytest-asyncio==0.24.0
 + pytest-cov==5.0.0
 + pytest-mock==3.14.0
 + pytest-xdist==3.6.1
 + python-dateutil==2.9.0.post0
 + python-dotenv==1.0.1
 + python-slugify==8.0.4
 + pytimeparse==1.1.8
 + pytz==2024.2
 + pyyaml==6.0.2
 + rapidfuzz==3.10.1
 + referencing==0.35.1
 + requests==2.32.3
 + requests-toolbelt==1.0.0
 + responses==0.23.1
 + rich==13.9.4
 + rpds-py==0.21.0
 + shellingham==1.5.4
 + six==1.16.0
 + sniffio==1.3.1
 + snowflake-connector-python==3.12.3
 + snowflake-sqlalchemy==1.7.0
 + sortedcontainers==2.4.0
 + sqlalchemy==2.0.36
 + sqlglot==25.32.1
 + sqlglotrs==0.3.0
 + sqlparse==0.5.2
 + starlette==0.41.3
 + structlog==24.4.0
 + syrupy==4.8.0
 + tabulate==0.9.0
 + text-unidecode==1.3
 + tomli==2.1.0
 + tomlkit==0.13.2
 + toposort==1.10
 + tox==4.23.2
 + tqdm==4.67.1
 + typer==0.13.1
 + types-protobuf==5.28.3.20241030
 + types-pyyaml==6.0.12.20240917
 + typing-extensions==4.12.2
 + tzdata==2024.2
 + universal-pathlib==0.2.5
 + urllib3==2.2.3
 + uvicorn==0.32.1
 + uvloop==0.21.0
 + virtualenv==20.28.0
 + watchdog==5.0.3
 + watchfiles==1.0.0
 + websockets==14.1
 + yarl==1.18.0
 + zipp==3.21.0

What did you do?

the pyopenssl pin in this package is pyOpenSSL>=16.2.0,<25.0.0

but if you install a version of pyOpenSSL<23 you get the following error on import

[2024-11-27T18:38:44Z]     import snowflake.connector
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/snowflake/connector/__init__.py:19: in <module>
[2024-11-27T18:38:44Z]     from .connection import SnowflakeConnection
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/snowflake/connector/connection.py:37: in <module>
[2024-11-27T18:38:44Z]     from .auth import (
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/snowflake/connector/auth/__init__.py:7: in <module>
[2024-11-27T18:38:44Z]     from ._auth import Auth, get_public_key_fingerprint, get_token_from_private_key
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/snowflake/connector/auth/_auth.py:55: in <module>
[2024-11-27T18:38:44Z]     from ..network import (
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/snowflake/connector/network.py:21: in <module>
[2024-11-27T18:38:44Z]     import OpenSSL.SSL
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/OpenSSL/__init__.py:8: in <module>
[2024-11-27T18:38:44Z]     from OpenSSL import crypto, SSL
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/OpenSSL/crypto.py:1570: in <module>
[2024-11-27T18:38:44Z]     class X509StoreFlags(object):
[2024-11-27T18:38:44Z] .tox/py311/lib/python3.11/site-packages/OpenSSL/crypto.py:1589: in X509StoreFlags
[2024-11-27T18:38:44Z]     NOTIFY_POLICY = _lib.X509_V_FLAG_NOTIFY_POLICY
[2024-11-27T18:38:44Z] E   AttributeError: module 'lib' has no attribute 'X509_V_FLAG_NOTIFY_POLICY'

What did you expect to see?

no errors on all pinned versions of pyopenssl

Can you set logging to DEBUG and collect the logs?

import logging
import os

for logger_name in ('snowflake.connector',):
    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)
gibsondan commented 3 days ago

pyOpenSSL>=22.1.0 appears to be the minimum version that imports

I suspect the release of cryptography 44 today may have suddenly caused a lot of people to run into this

teej commented 3 days ago

Thanks @gibsondan using pyOpenSSL>=22.1.0 fixed this issue for me.