question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleNotFoundError: import of fnmatch halted; None in sys.modules

See original GitHub issue

I’m trying to use records with Snowflake (dwh solution in the cloud), and I do get results but I always get the ModuleNotFoundError error.

It works without any problems when I use just SqlAlchemy using snowflake-sqlalchemy, so that makes me think it’s something records specific. I really like the product and, although my resources are limited, I’m willing to assist or provide more information if requested.

I’m running Python 3.7.2, installed through homebrew, in a virtualenv on MacOS 10.14.3.

Installed packages:

pip install records snowflake-sqlalchemy

Code to reproduce (credentials and account are obviously not the ones I use):

import records
from sqlalchemy import create_engine

connection_params = dict(
    user='user',
    password='password',
    account='abc123',
    database='DWH',
    schema='SCHEMA'
)

connection_string = 'snowflake://{user}:{password}@{account}/{database}/{schema}'
db_string = connection_string.format(**connection_params)

query = 'select * from table limit 10'

db = records.Database(db_string)
rows = db.query(query)
for row in rows:
    print(row)

Stacktrace

Exception during reset or similar
Traceback (most recent call last):
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/sqlalchemy/pool.py", line 742, in _finalize_fairy
    fairy._reset(pool)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/sqlalchemy/pool.py", line 929, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 486, in do_rollback
    dbapi_connection.rollback()
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/connection.py", line 508, in rollback
    self.cursor().execute("ROLLBACK")
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/cursor.py", line 479, in execute
    _is_put_get=_is_put_get)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/cursor.py", line 369, in _execute_helper
    _no_results=_no_results)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/connection.py", line 784, in cmd_query
    _include_retry_params=True)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 313, in request
    timeout=timeout, _include_retry_params=_include_retry_params)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 530, in _post_request
    _include_retry_params=_include_retry_params)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 608, in fetch
    **kwargs)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 685, in _request_exec_wrapper
    raise e
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 648, in _request_exec_wrapper
    **kwargs)
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 873, in _request_exec
    raise err
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/snowflake/connector/network.py", line 776, in _request_exec
    auth=SnowflakeAuth(token),
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/botocore/vendored/requests/sessions.py", line 456, in request
    prep.url, proxies, stream, verify, cert
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/botocore/vendored/requests/sessions.py", line 614, in merge_environment_settings
    env_proxies = get_environ_proxies(url) or {}
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/botocore/vendored/requests/utils.py", line 534, in get_environ_proxies
    if should_bypass_proxies(url):
  File "/Users/optroodt/virtualenvs/records/lib/python3.7/site-packages/botocore/vendored/requests/utils.py", line 523, in should_bypass_proxies
    bypass = proxy_bypass(netloc)
  File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 2610, in proxy_bypass
    return proxy_bypass_macosx_sysconf(host)
  File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 2587, in proxy_bypass_macosx_sysconf
    return _proxy_bypass_macosx_sysconf(host, proxy_settings)
  File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 2534, in _proxy_bypass_macosx_sysconf
    from fnmatch import fnmatch
ModuleNotFoundError: import of fnmatch halted; None in sys.modules

Thanks!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:13

github_iconTop GitHub Comments

9reactions
peterolivecommented, May 22, 2019

@optroodt You need to close the connection and dispose the engine. Try add the following at the end:

connection.close()
engine.dispose()
1reaction
samiskencommented, Mar 3, 2020

@peterolive thanks! This solved my issue with this error

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot find time module when changed sys.modules[__name__]
A slightly terrible fix: attach it to the class Hello . import sys class Hello: import time #Yes, the import statement in the...
Read more >
Issue 31642: None value in sys.modules no longer blocks import
An import error raised when import was blocked by setting None in sys. modules was not silenced because it has different error message....
Read more >
import of time halted; none in sys.modules - 七牛云
ModuleNotFoundError : import of time halted; none in sys.modules.
Read more >
ModuleNotFoundError: import of time ha.. - W3coded.com
ModuleNotFoundError : import of time halted; None in sys.modules occured when Object gets out of scope(__del__) python,modulenotfounderror,6,3.
Read more >
vocab.txt - Hugging Face
... shape ##vel logger specifi ##ant files count import iter ##oc exist debug ... datas lines ##ments dtype refer scal orig sys graph...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found