What did you do?
Using Pillow to read the exif metadata of a jpg image
What did you expect to happen?
Expected the metadata to converted into bytes
What actually happened?
Issue in the tobytes() function reading the metadata
python3.9/site-packages/PIL/TiffImagePlugin.py", line 895, in tobytes
"<table: %d bytes>" % len(data) if len(data) >= 16 else str(values)
TypeError: object of type 'IFDRational' has no len()
What are your OS, Python and Pillow versions?
- OS: Ubuntu 22.04.2
- Python: 3.9.9
- Pillow: 9.4.0
from io import BytesIO
from pathlib import Path
from PIL import Image
with Path(__file__).with_name("sample.jpg").open("rb") as fp:
image = Image.open(BytesIO(fp.read()))
image.getexif().tobytes()
a whited out 1x1 pixel image with the metadata that has this problem is attached below

What did you do?
Using Pillow to read the exif metadata of a jpg image
What did you expect to happen?
Expected the metadata to converted into bytes
What actually happened?
Issue in the tobytes() function reading the metadata
What are your OS, Python and Pillow versions?
a whited out 1x1 pixel image with the metadata that has this problem is attached below