I get TypeError in my Django project when Debug=False
so I have this Django project, using django-cloudinary-storage
. But when I turn on the Debug
, I get this error saying : TypeError: expected str, bytes or os.PathLike object, not NoneType.
I don't understand what I did wrong. could you take a look at the traceback and see what went wrong? Thanks.
If you need any further info, please let me know.
Traceback (most recent call last): File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner self.run() File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run self._target(*self._args, **self._kwargs) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 157, in inner_run handler = self.get_handler(*args, **options) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 31, in get_handler handler = super().get_handler(*args, **options) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 78, in get_handler return get_internal_wsgi_application() File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/core/servers/basehttp.py", line 47, in get_internal_wsgi_application return import_string(app_path) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/utils/module_loading.py", line 30, in import_string return cached_import(module_path, class_name) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/utils/module_loading.py", line 15, in cached_import import_module(module_path) File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/Users/ryanoh/Projects/crystalize/crystalize/wsgi.py", line 16, in <module> application = get_wsgi_application() File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application return WSGIHandler() File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/core/handlers/wsgi.py", line 126, in __init__ self.load_middleware() File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/core/handlers/base.py", line 61, in load_middleware mw_instance = middleware(adapted_handler) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/middleware.py", line 51, in __init__ self.add_files(self.static_root, prefix=self.static_prefix) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/base.py", line 113, in add_files self.update_files_dictionary(root, prefix) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/base.py", line 125, in update_files_dictionary self.add_file_to_dictionary(url, path, stat_cache=stat_cache) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/base.py", line 136, in add_file_to_dictionary static_file = self.get_static_file(path, url, stat_cache=stat_cache) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/base.py", line 210, in get_static_file self.add_cache_headers(headers, path, url) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/base.py", line 231, in add_cache_headers if self.immutable_file_test(path, url): File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/middleware.py", line 146, in immutable_file_test static_url = self.get_static_url(name_without_hash) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/whitenoise/middleware.py", line 169, in get_static_url return decode_if_byte_string(staticfiles_storage.url(name)) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 166, in url return self._url(self.stored_name, name, force) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 145, in _url hashed_name = hashed_name_func(*args) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 394, in stored_name self.hashed_name(name, content=None, filename=intermediate_name) File "/Users/ryanoh/Projects/crysenv/lib/python3.9/site-packages/cloudinary_storage/storage.py", line 286, in hashed_name content = open(absolute_path, 'rb') TypeError: expected str, bytes or os.PathLike object, not NoneType
Answers
-
Hey Ryan,
This error generally stems when trying to access a file but a
None
value is provided as the filename. We would need to figure out where theNone
value is coming from and correct the assignment. For example what the value of the open method is. Would you be able to look into any file accessing methods/functions and let us know if there are any hints there/share relevant code from those sections?0