[solved] ValueError: bad marshal data (unknown type code)

Somehow my bench command environment become corrupted -

frappe@ubuntu1804lts:~/frappe-bench$ bench --help
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py”, line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py”, line 2793, in load_entry_point
return ep.load()
File “/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py”, line 2411, in load
return self.resolve()
File “/usr/local/lib/python3.6/dist-packages/pkg_resources/init.py”, line 2417, in resolve
module = import(self.module_name, fromlist=[‘name’], level=0)
File “/home/frappe/.bench/bench/cli.py”, line 3, in
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe, log
File “/home/frappe/.bench/bench/utils.py”, line 1, in
import os, sys, shutil, subprocess, logging, itertools, requests, json, platform, select, pwd, grp, multiprocessing, hashlib, glob
File “/usr/local/lib/python3.6/dist-packages/requests/init.py”, line 95, in
from urllib3.contrib import pyopenssl
File “/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py”, line 46, in
import OpenSSL.SSL
File “/usr/lib/python3/dist-packages/OpenSSL/init.py”, line 8, in
from OpenSSL import crypto, SSL
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 779, in get_code
File “”, line 487, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

To recompile the code didn’t solve the problem:

frappe@ubuntu1804lts:~/frappe-bench$ find /usr -name ‘*.pyc’ -delete

frappe@ubuntu1804lts:~/frappe-bench$ pip list
Traceback (most recent call last):
File “/usr/local/bin/pip”, line 11, in
sys.exit(main())
File “/usr/local/lib/python3.6/dist-packages/pip/_internal/main.py”, line 45, in main
command = create_command(cmd_name, isolated=(“–isolated” in cmd_args))
File “/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/init.py”, line 96, in create_command
module = importlib.import_module(module_path)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/list.py”, line 13, in
from pip._internal.cli.req_command import IndexGroupCommand
File “/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/req_command.py”, line 20, in
from pip._internal.network.session import PipSession
File “/usr/local/lib/python3.6/dist-packages/pip/_internal/network/session.py”, line 17, in
from pip._vendor import requests, six, urllib3
File “/usr/local/lib/python3.6/dist-packages/pip/_vendor/requests/init.py”, line 97, in
from pip._vendor.urllib3.contrib import pyopenssl
File “/usr/local/lib/python3.6/dist-packages/pip/_vendor/urllib3/contrib/pyopenssl.py”, line 46, in
import OpenSSL.SSL
File “/usr/lib/python3/dist-packages/OpenSSL/init.py”, line 8, in
from OpenSSL import crypto, SSL
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 779, in get_code
File “”, line 487, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

But a reinstall of the openssl library did fix the problem:

frappe@ubuntu1804lts:~/frappe-bench$ sudo apt remove python3-openssl
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
landscape-common python3-openssl python3-service-identity python3-twisted
0 upgraded, 0 newly installed, 4 to remove and 10 not upgraded.
After this operation, 13.4 MB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database … 142908 files and directories currently installed.)
Removing landscape-common (18.01-0ubuntu3.4) …
Removing python3-twisted (17.9.0-2) …
Removing python3-service-identity (16.0.0-2) …
Removing python3-openssl (17.5.0-1ubuntu1) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
frappe@ubuntu1804lts:~/frappe-bench$ sudo apt install python3-openssl
Reading package lists… Done
Building dependency tree
Reading state information… Done
Suggested packages:
python-openssl-doc python3-openssl-dbg
The following NEW packages will be installed:
python3-openssl
0 upgraded, 1 newly installed, 0 to remove and 10 not upgraded.
Need to get 41.5 kB of archives.
After this operation, 229 kB of additional disk space will be used.
Get:1 Index of /ubuntu bionic/main amd64 python3-openssl all 17.5.0-1ubuntu1 [41.5 kB]
Fetched 41.5 kB in 1s (52.9 kB/s)
Selecting previously unselected package python3-openssl.
(Reading database … 141876 files and directories currently installed.)
Preparing to unpack …/python3-openssl_17.5.0-1ubuntu1_all.deb …
Unpacking python3-openssl (17.5.0-1ubuntu1) …
Setting up python3-openssl (17.5.0-1ubuntu1) …

Voila fixed!

frappe@ubuntu1804lts:~/frappe-bench$ bench --help
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 bench.
download-translations Download latest translations
exclude-app Exclude app from updating
find Finds benches recursively from location