python fit_tool error decoding only with garming forerunner 965 and 935 FIT file

I succesfuly run the modify_activity example from fit_tools which decode a fit file (Activity.fit) then save the file with a new name, and checke with a fit reader with no errors. I could do that too with mywhoosh fit files with no errors. However, when I provide my own garmit file from a forerunner 965, I get a decode error, generated by the fit_tool file field.py. It appears that the error is related to the wrong format in the decode option. Any hints?

This is the error message:

string_container = bytes_buffer.decode('utf-8')
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 33: invalid continuation byte


This is the program

from fit_tool.fit_file import FitFile
from fit_tool.fit_file_builder import FitFileBuilder
from fit_tool.profile.messages.record_message import RecordMessage, RecordHeartRateField, RecordPowerField
import copy

def main():
"""The following program reads all the bytes from a FIT formatted file and then
decodes these bytes to create a FIT file object. We then build a modified FIT file
based on a variety of criteria (see comments below). Finally we output
the modified data to a new FIT file.
"""
path = '../fit_tool/tests/data/sdk/2024-03-16-14-21.fit' # original example with Activity.fit
fit_file = FitFile.from_file(path)

builder = FitFileBuilder(auto_define=False)
mod_records = copy.deepcopy(fit_file.records)
for record in fit_file.records:
message = record.message
include_record = True

if message.global_id == RecordMessage.ID:
# Remove the heart rate field from all record definition and data messages
message.remove_field(RecordHeartRateField.ID)

if isinstance(message, RecordMessage):
# remove records where the power is too high
power_field = message.get_field(RecordPowerField.ID)
if power_field and power_field.is_valid():
power = power_field.get_value()
if power > 800:
include_record = False

if include_record:
builder.add(message)

modified_file = builder.build()
modified_file.to_file('../fit_tool/tests/out/modified_activity2.fit')

fit_file2 = FitFile.from_file('../fit_tool/tests/out/modified_activity.fit')


if __name__ == "__main__":
main()

2024-03-16-14-21.zip

  • The Python SDK that you are using is not one of the SDKs published by Garmin. There is contact info for the developer listed in PyPI for that package. You may want to reach out to the developer directly.

  • My apologies if the post looks out of place. But, since python programmers are out of options for encoding FIT files with the official python SDK that it is only for decoding, I thought that asking in this forum I may get some insides on my particular issue with the fit tool, in case anyone has experienced similar issues with a fit file coming from a Garmin watch.  I already had submitted an email to the fit_tool programmer and also posted in their web the issue long time ago but did not get an answer (is the development dead?). Garming customer help directed me to ask the question on this forum.  Again, my apologies.

  • Anything FIT SDK related is fair game for discussion in the FIT SDK forum. That includes FIT SDKs published by third-parties. I am not sure if the developer of that package is active in the forum or not, so reaching out to them directly might actually get you a faster response.