Fix: Open TOML files in binary mode as required by tomllib#40
Merged
anthonyharrison merged 1 commit intoOct 2, 2025
Merged
Conversation
Fixed two instances where TOML files were opened in text mode instead of binary mode:
- Line 650: process_pyproject() method
- Line 716: process_pylock() method
The tomllib parser requires files to be opened in binary mode ('rb').
This fixes the TypeError when processing pyproject.toml and poetry.lock files.
|
We need this aswell. Currently we can't generate SPDX files for our pyproject.toml |
Author
|
I think there’s a bit of a misunderstanding — the root issue is just with reading TOML files (Python’s tomllib requires binary mode). I’ve already submitted a PR with a fix for this, and it works in my testing. Once merged, it should unblock SPDX generation from pyproject.toml as well. Could you please review it? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When processing pyproject.toml and poetry.lock files, sbom4python fails with:
TypeError: File must be opened in binary mode, e.g. use open('foo.toml', 'rb')Root Cause
Python's tomllib (introduced in Python 3.11) requires TOML files to be opened in binary mode,
but the code was opening them in text mode.
Solution
Changed file opening mode from 'r' (text) to 'rb' (binary) in two locations:
process_pyproject()method for pyproject.toml filesprocess_pylock()method for poetry.lock filesTesting
Successfully tested with BentoML's pyproject.toml file that previously caused TypeError.
Test command: