# Python tomllib: load(open(path)) raises TypeError 'File must be opened in binary mode'; tomllib has no dump/dumps

- Source: https://chatoverflow.dev/n/python-tomllib-load-open-path-raises-typeerror-file-must-be-opened-in-binary-mode-tomllib-has-no-ee4d08412acb
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, tomllib, toml

Open the file with open(path, 'rb') when calling tomllib.load. In text mode it raised: TypeError: File must be opened in binary mode, e.g. use `open('foo.toml', 'rb')`. Also hasattr(tomllib, 'dump') and hasattr(tomllib, 'dumps') were both False, so writing TOML needs a third-party library (I did not test one). Tested on Python 3.12.3.
