Bench commands all abort with this ValueError: No JSON object could be decoded

Hi! Somehow I broke my bench environment -

Any command I run aborts like this:

(env) frappe@ubuntu:~/frappe-bench$ bench --help

/home/frappe/.bench/bench/cli.py(110)get_frappe_commands()
-> python = get_env_cmd(‘python’, bench_path=bench_path)
(Pdb) c
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/home/frappe/.bench/bench/cli.py”, line 28, in cli
elif len(sys.argv) > 1 and sys.argv[1] in get_frappe_commands():
File “/home/frappe/.bench/bench/cli.py”, line 110, in get_frappe_commands
python = get_env_cmd(‘python’, bench_path=bench_path)
File “/usr/lib/python2.7/json/init.py”, line 339, in loads
return _default_decoder.decode(s)
File “/usr/lib/python2.7/json/decoder.py”, line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python2.7/json/decoder.py”, line 382, in raw_decode
raise ValueError(“No JSON object could be decoded”)
ValueError: No JSON object could be decoded

I am debugging the code to find the problem - is anyone familiar with this or the fix here?

Thanks!

https://discuss.erpnext.com/t/bench-update-error-no-json-object-could-be-decoded/17200

I suspect you have seen this and checked , a syntax error is a likely culprit…

Thanks for your suggestion smino!

The problem had to do with an unexpected command prompt header(??) piped to stdout (see my session below.)

A ‘git reset --hard’, to back out my changes to apps/erpnext and apps/frappe, got rid of the problem.

I checked for a malformed json file but nothing showed up:

(env) frappe@ubuntu:~/frappe-bench$ find . -name ‘*.json’ | xargs jsonlint

For the record I am on the staging branch:
(env) frappe@ubuntu:~/frappe-bench$ bench version
erpnext 11.0.3-beta.2
frappe 11.0.0-beta

Here’s is a snippet from my debug session:

(env) frappe@ubuntu:~/frappe-bench$ bench --help

/home/frappe/.bench/bench/utils.py(365)get_cmd_output()
-> output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=open(os.devnull, ‘wb’)).strip()
(Pdb) l
360
361 def get_cmd_output(cmd, cwd=’.’):
362 try:
363 import pdb
364 pdb.set_trace()
365 -> output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=open(os.devnull, ‘wb’)).strip()
366 output = output.decode(‘utf-8’)
367 return output
368 except subprocess.CalledProcessError as e:
369 if e.output:
370 print(e.output)
(Pdb) n
/home/frappe/.bench/bench/utils.py(366)get_cmd_output()
-> output = output.decode(‘utf-8’)
(Pdb) output
‘\x1b]0;IPython: frappe-bench/sites\x07[“restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “reload-doctype”, “mysql”, “clear-limits”, “destroy-all-sessions”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “run-setup-wizard-ui-test”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “set-limits”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “new-language”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “watch”, “run-patch”, “serve”, “import-csv”, “import-doc”, “trigger-scheduler-event”, “show-pending-jobs”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “mariadb”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “list-apps”, “execute”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “request”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “reload-doctype”, “mysql”, “clear-limits”, “destroy-all-sessions”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “run-setup-wizard-ui-test”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “set-limits”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “new-language”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “watch”, “run-patch”, “serve”, “import-csv”, “import-doc”, “trigger-scheduler-event”, “show-pending-jobs”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “mariadb”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “list-apps”, “execute”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “request”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “make-demo”]’
(Pdb) l
361 def get_cmd_output(cmd, cwd=’.’):
362 try:
363 import pdb
364 pdb.set_trace()
365 output = subprocess.check_output(cmd, cwd=cwd, shell=True, stderr=open(os.devnull, ‘wb’)).strip()
366 -> output = output.decode(‘utf-8’)
367 return output
368 except subprocess.CalledProcessError as e:
369 if e.output:
370 print(e.output)
371 raise
(Pdb) cmd
‘/home/frappe/frappe-bench/env/bin/python -m frappe.utils.bench_helper get-frappe-commands’

(Pdb) output
‘\x1b]0;IPython: frappe-bench/sites\x07[“restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “reload-doctype”, “mysql”, “clear-limits”, “destroy-all-sessions”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “run-setup-wizard-ui-test”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “set-limits”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “new-language”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “watch”, “run-patch”, “serve”, “import-csv”, “import-doc”, “trigger-scheduler-event”, “show-pending-jobs”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “mariadb”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “list-apps”, “execute”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “request”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “reload-doctype”, “mysql”, “clear-limits”, “destroy-all-sessions”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “run-setup-wizard-ui-test”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “set-limits”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “new-language”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “watch”, “run-patch”, “serve”, “import-csv”, “import-doc”, “trigger-scheduler-event”, “show-pending-jobs”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “mariadb”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “list-apps”, “execute”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “request”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “make-demo”]’

(Pdb) !output=’[“restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “request”, “mysql”, “clear-limits”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “new-language”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “mariadb”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “run-setup-wizard-ui-test”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “serve”, “run-patch”, “watch”, “import-csv”, “list-apps”, “trigger-scheduler-event”, “show-pending-jobs”, “execute”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “set-limits”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “import-doc”, “destroy-all-sessions”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “reload-doctype”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “request”, “mysql”, “clear-limits”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “new-language”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “mariadb”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “run-setup-wizard-ui-test”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “serve”, “run-patch”, “watch”, “import-csv”, “list-apps”, “trigger-scheduler-event”, “show-pending-jobs”, “execute”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “set-limits”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “import-doc”, “destroy-all-sessions”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “reload-doctype”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “make-demo”]’

(Pdb) output
‘[“restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “request”, “mysql”, “clear-limits”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “new-language”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “mariadb”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “run-setup-wizard-ui-test”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “serve”, “run-patch”, “watch”, “import-csv”, “list-apps”, “trigger-scheduler-event”, “show-pending-jobs”, “execute”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “set-limits”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “import-doc”, “destroy-all-sessions”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “reload-doctype”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “restore”, “setup-help”, “set-admin-password”, “run-tests”, “migrate”, “request”, “mysql”, “clear-limits”, “new-site”, “add-system-manager”, “publish-realtime”, “add-to-email-queue”, “clear-website-cache”, “set-maintenance-mode”, “new-language”, “worker”, “disable-scheduler”, “remove-from-installed-apps”, “set-config”, “drop-site”, “use”, “mariadb”, “console”, “doctor”, “run-ui-tests”, “schedule”, “disable-user”, “reset-perms”, “version”, “build”, “ready-for-migration”, “bulk-rename”, “export-doc”, “run-setup-wizard-ui-test”, “set-limit”, “uninstall-app”, “clear-cache”, “build-message-files”, “serve”, “run-patch”, “watch”, “import-csv”, “list-apps”, “trigger-scheduler-event”, “show-pending-jobs”, “execute”, “scheduler”, “install-app”, “auto-deploy”, “build-docs”, “set-limits”, “make-app”, “reinstall”, “export-json”, “purge-jobs”, “import-doc”, “destroy-all-sessions”, “import-translations”, “jupyter”, “enable-scheduler”, “setup-global-help”, “reload-doctype”, “get-untranslated”, “update-translations”, “export-csv”, “rebuild-global-search”, “reload-doc”, “export-fixtures”, “backup”, “set-last-active-for-user”, “make-demo”]’

(Pdb) c
Usage: [OPTIONS] COMMAND [ARGS]…

Bench manager for Frappe

Options:
–version
–help Show this message and exit.

Commands:
backup backup site
backup-all-sites backup all sites
config change bench configuration
disable-production Disables production environment for the…
download-translations Download latest translations
exclude-app Exclude app from updating
get-app clone an app from the internet and set it up…
include-app Include app from updating
init Create a New Bench Instance.
install Install system dependancies
migrate-env Migrate Virtual Environment to desired Python…
new-app start a new app
prepare-beta-release Prepare major beta release from develop…
release Release app (internal to the Frappe team)
remote-reset-url Reset app remote url to frappe official
remote-set-url Set app remote url
remote-urls Show apps remote url
remove-app completely remove app from bench
renew-lets-encrypt Renew Let’s Encrypt certificate
restart Restart supervisor processes or systemd units
retry-upgrade
set-default-site Set default site for bench
set-mariadb-host Set MariaDB host for bench
set-nginx-port Set nginx port for site
set-ssl-certificate Set ssl certificate path for site
set-ssl-key Set ssl certificate private key path for site
set-url-root Set url root for site
setup Setup bench
shell
src Prints bench source folder path, which can be…
start Start Frappe development processes
switch-to-branch Switch all apps to specified branch, or…
switch-to-develop Switch frappe and erpnext to develop branch
switch-to-master Switch frappe and erpnext to master branch
update Update bench
()

Notice in the above session that removing the command prompt
\x1b]0;IPython: frappe-bench/sites\x07

and the ‘bench --help’ script runs as expected…

“Somehow I broke my bench environment -”

FWIW for emacs users this likely caused the problem - ansi color settings in the ipython prompt

Hii @clarkej,

Did you tried to change site config? Make sure your site config in proper format.

Thanks all is well now -

The error arose with bench commands captured to stdout that violated JSON format due to a ‘bad’ ipython command prompt. (The emacs editor I use changed the command prompt that broke my bench command environment…)

json.loads is used as a ‘data transfer object’ to send and receive (key, value) dict lists, as this search shows

(env) frappe@ubuntu:~/frappe-bench$ find . -name ‘*.py’ | xargs grep json.loads

1 Like