Mercurial > kallithea
changeset 8457:c91f5f36fb2b stable
api: fix 'kallithea-api --save-config'
Commit eca0cb56a822 attempted to fix a type inconsistency, which caused
failure in the 'kallithea-api' tool when using '--save-config', but this
unfortunately did not fix the problem completely.
Following error still appeared:
Traceback (most recent call last):
File ".../bin/kallithea-api", line 33, in <module>
sys.exit(load_entry_point('Kallithea', 'console_scripts', 'kallithea-api')())
File ".../bin/kallithea_api.py", line 84, in main
'apihost': args.apihost})
File ".../bin/base.py", line 104, in __init__
self.make_config(config)
File ".../bin/base.py", line 132, in make_config
ext_json.dump(config, f, indent=4)
File "/usr/lib/python3.7/json/__init__.py", line 180, in dump
fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
The json module documentation says:
https://docs.python.org/3.7/library/json.html#basic-usage
"The json module always produces str objects, not bytes objects. Therefore,
fp.write() must support str input."
Therefore, instead of opening the file in binary mode and writing bytes,
open it in text mode and write strings.
For symmetry reasons, we make the same change when _loading_ the config
file, but this code worked regardless.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Thu, 10 Sep 2020 20:17:18 +0200 |
parents | eca0cb56a822 |
children | cecb8eeb07a2 |
files | kallithea/bin/base.py |
diffstat | 1 files changed, 3 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/bin/base.py Sun Jul 26 00:03:12 2020 +0200 +++ b/kallithea/bin/base.py Thu Sep 10 20:17:18 2020 +0200 @@ -128,9 +128,9 @@ update = False if os.path.exists(self._conf_name): update = True - with open(self._conf_name, 'wb') as f: + with open(self._conf_name, 'w') as f: ext_json.dump(config, f, indent=4) - f.write(b'\n') + f.write('\n') if update: sys.stdout.write('Updated config in %s\n' % self._conf_name) @@ -159,7 +159,7 @@ Loads config from file and returns loaded JSON object """ try: - with open(self._conf_name, 'rb') as conf: + with open(self._conf_name, 'r') as conf: return ext_json.load(conf) except IOError as e: #sys.stderr.write(str(e) + '\n')