Trouble setting tags

Hi there, I'm relatively new to Python and I've been working on a script to write EXIF tags to JPGs using exif 1.3.1. I'm getting a crash when attempting to set the tags though.

Here's a minimal code example:

with open(file, 'rb') as image_file:
    image = Image(image_file)

# logic here to get the tags from an API and prepare a dictionary called diff
# which contains the tags to be added to the JPG

print(diff)

# Apply the diff to the image
for key, value in diff.items():
    image.set(key, value)

# do the write
with open(file, 'wb') as image_file:
    image_file.write(image.get_file())

And here's the output of my script:

{'lens_make': 'Canon', 'copyright': '© 2021 Jonathan Gazeley', 'flash': True, 'artist': 'Jonathan Gazeley', 'lens_serial_number': '11111', 'gps_latitude': '51.458634956614560', 'datetime_original': '2021-08-25T09:21:00Z', 'focal_length': 50, 'iso_speed': 200, 'make': 'Agfa', 'image_unique_id': '3498daa8-f7ce-4d9d-a6fb-4280046488e9', 'body_serial_number': '234', 'user_comment': '', 'lens_model': '50mm f/1.8', 'model': 'Clicky', 'gps_longitude': '-2.520624278071962'}

Traceback (most recent call last):
  File "/home/jonathan/.cache/pypoetry/virtualenvs/tagger-cli-SSoXMnv6-py3.9/lib/python3.9/site-packages/exif/_app1_metadata.py", line 557, in __setattr__
    ifd_tag = self.ifd_tags[attribute_id]
KeyError: 42035

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jonathan/.cache/pypoetry/virtualenvs/tagger-cli-SSoXMnv6-py3.9/lib/python3.9/site-packages/exif/_app1_metadata.py", line 121, in _add_tag
    tag_type, ifd_number = ATTRIBUTE_TYPE_MAP[tag]
KeyError: 'lens_make'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jonathan/git/camerahub/tagger-cli/main.py", line 447, in <module>
    image.set(key, value)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/tagger-cli-SSoXMnv6-py3.9/lib/python3.9/site-packages/exif/_image.py", line 251, in set
    self.__setattr__(attribute, value)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/tagger-cli-SSoXMnv6-py3.9/lib/python3.9/site-packages/exif/_image.py", line 113, in __setattr__
    setattr(self._segments["APP1"], key.lower(), value)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/tagger-cli-SSoXMnv6-py3.9/lib/python3.9/site-packages/exif/_app1_metadata.py", line 560, in __setattr__
    self._add_tag(key, value)
  File "/home/jonathan/.cache/pypoetry/virtualenvs/tagger-cli-SSoXMnv6-py3.9/lib/python3.9/site-packages/exif/_app1_metadata.py", line 123, in _add_tag
    raise AttributeError("cannot add attribute {0} to image".format(tag))
AttributeError: cannot add attribute lens_make to image

Versions of libraries in use:

[jonathan@poseidon tagger-cli]$ poetry show
certifi            2021.5.30 Python package for providing Mozilla's CA Bundle.
charset-normalizer 2.0.4     The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
exif               1.3.1     Read and modify image EXIF metadata using Python.
idna               3.2       Internationalized Domain Names in Applications (IDNA)
plum-py            0.7.0     Pack/Unpack Memory.
requests           2.26.0    Python HTTP for Humans.
urllib3            1.26.6    HTTP library with thread-safe connection pooling, file post, and more.
uuid               1.30      UUID object and generation functions (Python 2.3 or higher)

Do you know what's going wrong here? Thanks

Edited by Jonathan