snowflake-connector-python: SNOW-634755: ImportError: cannot import name 'NamedTuple' from 'typing_extensions'

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

Issue happened on vm, but reproduces on my mac

Python 3.9.7 (default, Oct 13 2021, 06:45:31) [Clang 13.0.0 (clang-1300.0.29.3)]

  1. What operating system and processor architecture are you using?

macOS-12.4-x86_64-i386-64bit

  1. What are the component versions in the environment (pip freeze)?

from mac laptop - hard to pull from vm where issue happened aniso8601==9.0.1 appnope==0.1.2 Authlib==0.15.4 backcall==0.2.0 boto3==1.16.10 botocore==1.19.10 certifi==2021.10.8 cffi==1.14.6 charset-normalizer==2.0.7 cryptography==35.0.0 cypari==2.4.1 decorator==4.4.2 future==0.18.2 FXrays==1.3.5 graphene==3.0 graphql-core==3.1.7 graphql-relay==3.1.5 idna==3.2 ipython==7.21.0 ipython-genutils==0.2.0 jedi==0.18.0 jmespath==0.10.0 networkx==2.5 oauthlib==3.1.1 parso==0.8.1 pexpect==4.8.0 pickleshare==0.7.5 plink==2.3.1 prompt-toolkit==3.0.17 ptyprocess==0.7.0 pycparser==2.20 Pygments==2.8.1 PyJWT==2.2.0 pypng==0.0.20 python-dateutil==2.8.1 python-snappy==0.6.0 requests==2.26.0 s3transfer==0.3.3 six==1.15.0 snappy-manifolds==1.1.2 spherogram==1.8.3 traitlets==5.0.5 typing_extensions==4.2.0 urllib3==1.25.11 wcwidth==0.2.5

  1. What did you do?
conn = snowflake.connector.connect(
        user=snowflake_user,
        role=snowflake_role,
        password=snowflake_pass,
        account=snowflake_acc,
        database=database,
        schema=schema
    )

fails with ImportError: cannot import name 'NamedTuple' from 'typing_extensions' (/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/typing_extensions.py)

Some root cause analysis from my side –

Latest version of Snowflake-connector (‘2.7.10’) includes cache.py, which imports NamedTuple

from typing_extensions import NamedTuple, Self https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/cache.py#L12

This fails if using typing_extensions < 4.3.0, as NamedTuple was added in this commit https://github.com/python/typing_extensions/commit/7c28357e412cef215a7d66c0ef69b568b316678b

I believe you need to change the requirements to be >= 4.3.0 for typing_extentions https://github.com/snowflakedb/snowflake-connector-python/blob/main/setup.cfg#L59

  1. What did you expect to see?

No error message when connecting to snowflake.

What should have happened and what happened instead?

Able to connect to snowflake.

  1. Can you set logging to DEBUG and collect the logs?

No - above root cause analysis in part 4 explains issue and how to fix it on Snowflake side.

— full failure traceback from vm starting with Snowflake code

File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/__init__.py", line 51, in Connect
--
return SnowflakeConnection(**kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 292, in __init__
self.connect(**kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 542, in connect
self.__open_connection()
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 781, in __open_connection
self._authenticate(auth_instance)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 1044, in _authenticate
self.__authenticate(self.__preprocess_auth_instance(auth_instance))
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/connection.py", line 1064, in __authenticate
auth.authenticate(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/auth.py", line 257, in authenticate
ret = self._rest._post_request(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 704, in _post_request
ret = self.fetch(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 794, in fetch
ret = self._request_exec_wrapper(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 917, in _request_exec_wrapper
raise e
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 837, in _request_exec_wrapper
return_object = self._request_exec(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 1116, in _request_exec
raise err
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/network.py", line 1018, in _request_exec
raw_ret = session.request(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/vendored/urllib3/connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/ssl_wrap_socket.py", line 78, in ssl_wrap_socket_with_ocsp
from .ocsp_asn1crypto import SnowflakeOCSPAsn1Crypto as SFOCSP
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/ocsp_asn1crypto.py", line 47, in <module>
from snowflake.connector.ocsp_snowflake import SnowflakeOCSP
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/ocsp_snowflake.py", line 71, in <module>
from .cache import SFDictCache
File "/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/snowflake/connector/cache.py", line 12, in <module>
from typing_extensions import NamedTuple, Self
ImportError: cannot import name 'NamedTuple' from 'typing_extensions' (/root/.pyenv/versions/3.9.12/lib/python3.9/site-packages/typing_extensions.py)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 27

Commits related to this issue

Most upvoted comments

pip install 'typing-extensions>=4.3.0' with version 2.7.10 should also do the trick.

We had to go back to 2.7.9

Same problem here, and !pip install ‘typing-extensions>=4.3.0’ did not solve it (using google colab) 😦

Same here the solution did not work for colab

We are also getting the same error all over the place. You probably need to update the requirements. Adding typing-extensions>=4.3.0 in our requirements.txt file and updated our MWAA environment fixed the issue.

pip install 'typing-extensions>=4.3.0' with version 2.7.10 should also do the trick.

This is the right solution, I forgot to add a lower pin to the new dependency. We’ll go ahead and release a new version with this fixed and yank 2.7.10!

Also experiencing the same error on google colab.