ModuleNotFoundError: No module named 'bleach.css_sanitizer'

Hello,

I have recently migrated from frappe version 14 to version 15 i have successfully upgraded to version 15 but when i did bench --site site.local migrate it gives me below error:

Traceback (most recent call last):
File “/usr/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/usr/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 114, in
main()
File “/home/nabeel/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 20, in main
click.Group(commands=commands)(prog_name=“bench”)
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/nabeel/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/commands/init.py”, line 29, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/commands/site.py”, line 686, in migrate
SiteMigration(
File “/home/nabeel/frappe-bench/apps/frappe/frappe/migrate.py”, line 186, in run
self.run_schema_updates()
File “/home/nabeel/frappe-bench/apps/frappe/frappe/migrate.py”, line 52, in wrapper
raise e
File “/home/nabeel/frappe-bench/apps/frappe/frappe/migrate.py”, line 44, in wrapper
ret = method(*args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/migrate.py”, line 117, in run_schema_updates
frappe.modules.patch_handler.run_all(
File “/home/nabeel/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 76, in run_all
run_patch(patch)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 62, in run_patch
if not run_single(patchmodule=patch):
File “/home/nabeel/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 152, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 190, in execute_patch
exec(patch, globals())
File “”, line 1, in
File “/home/nabeel/frappe-bench/apps/frappe/frappe/utils/typing_validations.py”, line 31, in wrapper
return func(*args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/init.py”, line 1419, in rename_doc
return rename_doc(
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/rename_doc.py”, line 215, in rename_doc
new_doc.add_comment(“Edit”, _(“renamed from {0} to {1}”).format(frappe.bold(old), frappe.bold(new)))
File “/home/nabeel/frappe-bench/apps/frappe/frappe/utils/typing_validations.py”, line 31, in wrapper
return func(*args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 1407, in add_comment
return frappe.get_doc(
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 295, in insert
self.run_before_save_methods()
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 1095, in run_before_save_methods
self.run_method(“validate”)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 966, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 1326, in composer
return composed(self, method, *args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 1308, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/nabeel/frappe-bench/apps/frappe/frappe/model/document.py”, line 963, in fn
return method_object(*args, **kwargs)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/core/doctype/comment/comment.py”, line 65, in validate
self.content = frappe.utils.sanitize_html(self.content, always_sanitize=True)
File “/home/nabeel/frappe-bench/apps/frappe/frappe/utils/html_utils.py”, line 153, in sanitize_html
from bleach.css_sanitizer import CSSSanitizer
ModuleNotFoundError: No module named ‘bleach.css_sanitizer’

i tried to install bleach using command:
pip install bleach

still getting the same error while migrate.

Please suggest a way out i am stuck at this.

Thanks.

@NKAfridi try to update the package . bench pip install --upgrade bleach

i tried to update the package using bench pip install --upgrade bleach it says:

Requirement already satisfied: bleach in ./env/lib/python3.10/site-packages (3.3.1)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x731bff0d3160>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/bleach/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x731bff0d3490>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/bleach/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x731bff0d37f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/bleach/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x731bff0d39a0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/bleach/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x731bff0d3b50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)': /simple/bleach/
Requirement already satisfied: packaging in ./env/lib/python3.10/site-packages (from bleach) (24.2)
Requirement already satisfied: six>=1.9.0 in ./env/lib/python3.10/site-packages (from bleach) (1.16.0)
Requirement already satisfied: webencodings in ./env/lib/python3.10/site-packages (from bleach) (0.5.1)

should i uninstall and install the package again? one more thing should i install html5lib library because bleach relies on that.