我有一个带有一些存储库信息的dict,我想把它写成一个json文件,但是在转储方法期间出现了这个错误:{TypeError} Object of type Commit is not JSON serializable
.
__repo_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
repo = Repo(__repo_path)
__tags = sorted(
(tag for tag in repo.tags if tag.commit.committed_datetime <= repo.head.commit.committed_datetime),
key=lambda t: t.commit.committed_datetime,)
try:
__current_branch = repo.active_branch
except TypeError as e:
__current_branch = "release"
SCM_DATA = {
"CHANGESET": repo.head.commit,
"BRANCH": __current_branch,
"TAG": __tags[-1],
"IS_DIRTY": repo.is_dirty(),
}
json_version = json.dumps(SCM_DATA)
我该如何修复它?
1条答案
按热度按时间8wigbo561#
确保使用名称/文本消息,而不是对象:
输出: