Site Not creating on server - Please help

bench new-site dev
MySQL root password:
Restoring Database file…
11.9KiB 0:00:00 [ 374MiB/s] [====================================================================================>] 100%

Installing frappe…
Updating DocTypes for frappe : [============= ] 34%Traceback (most recent call last):
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/utils.py”, line 205, in load_doctype_module
doctype_python_modules[key] = frappe.get_module(module_name)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/init.py”, line 981, in get_module
return importlib.import_module(modulename)
File “/home/ubuntu/frappe-bench/env/lib/python3.8/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 975, in _find_and_load_unlocked
File “”, line 671, in _load_unlocked
File “”, line 848, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/website/doctype/web_page/web_page.py”, line 10, in
from jinja2.exceptions import TemplateSyntaxError
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/jinja2/init.py”, line 12, in
from .environment import Environment
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/jinja2/environment.py”, line 25, in
from .defaults import BLOCK_END_STRING
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/jinja2/defaults.py”, line 3, in
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/jinja2/filters.py”, line 13, in
from markupsafe import soft_unicode
ImportError: cannot import name ‘soft_unicode’ from ‘markupsafe’ (/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/markupsafe/init.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.8/runpy.py”, line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/usr/lib/python3.8/runpy.py”, line 87, in _run_code
exec(code, run_globals)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 104, in
main()
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 19, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 829, in call
return self.main(*args, **kwargs)
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 782, in main
rv = self.invoke(ctx)
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/click/core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/commands/site.py”, line 38, in new_site
_new_site(db_name, site, mariadb_root_username=mariadb_root_username,
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/installer.py”, line 81, in _new_site
install_app(app, verbose=verbose, set_as_patched=not source_sql)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/installer.py”, line 162, in install_app
sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/sync.py”, line 70, in sync_for
import_file_by_path(doc_path, force=force, ignore_version=True, reset_permissions=reset_permissions)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 130, in import_file_by_path
import_doc(
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/import_file.py”, line 257, in import_doc
doc.insert()
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py”, line 270, in insert
self.run_post_save_methods()
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py”, line 1004, in run_post_save_methods
self.run_method(“on_update”)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py”, line 869, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py”, line 1161, in composer
return composed(self, method, *args, **kwargs)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py”, line 1144, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py”, line 863, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 326, in on_update
self.run_module_method(“on_doctype_update”)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py”, line 380, in run_module_method
module = load_doctype_module(self.name, self.module)
File “/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/utils.py”, line 207, in load_doctype_module
raise ImportError(‘Module import failed for {0} ({1})’.format(doctype, module_name + ’ Error: ’ + str(e)))
ImportError: Module import failed for Web Page (frappe.website.doctype.web_page.web_page Error: cannot import name ‘soft_unicode’ from ‘markupsafe’ (/home/ubuntu/frappe-bench/env/lib/python3.8/site-packages/markupsafe/init.py))

The Python module ‘MarkupSafe’, prior to version 2.1, had renamed the function ‘soft_unicode’ to ‘soft_str’. During the deprecation time period they had a mapper function from soft_unicode to soft_str. As of version 2.1 of MarkupSafe that mapper function was dropped.

Here is what I did to fix it. Locate the folder where you ran ‘bench init’. For me it was /srv/bench. Since I am using Debian Buster (10) the version of Python is 3.7. Then do this…

nano /srv/bench/erpnext/env/lib/python3.7/site-packages/markupsafe/__init__.py

At the bottom of the file, just above the try/catch block insert the following…

def soft_unicode(s: t.Any) -> str:
    import warnings

    warning_message = "'soft_unicode' has been renamed to 'soft_str'. It has been removed in MarkupSafe 2.1. It has been temporarily reinserted by a third party."
    warnings.warn(warning_message,DeprecationWarning,stacklevel=2,)

    return soft_str(s)

Then perform the following…

bench drop-site [site name]
bench  new-site [site name]

That should do it until the frappe/bench/ERPNext folks change the code to point to the new name of soft_str.

4 Likes

This worked for me! Thank you very much.

Hello
This is not working for me.
I don’t have that method.
I’ve python3.8.10 installed on the server.

@revant_one

Try to locate the file yourself in your frappe-bench folder using an IDE, I used VS code to open the file.
then add the code towards the end.

I had Python 3.8.10 installed too @Anshul_Sharma

Thanks a lot!!
This worked for me.

1 Like

This worked for me! Many thanks @padraig.fogarty.

Until this is resolved, I found another, maybe cleaner, option: