Skip to content

No units field for Apple FIT files #121

Description

@wjkaufman

I'm trying to parse a FIT file recorded by an Apple Watch, but I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-f31030851587> in <module>
----> 1 list(fit.get_messages())

~/opt/anaconda3/envs/body/lib/python3.8/site-packages/fitparse/base.py in get_messages(self, name, with_definitions, as_dict)
    432         # If there are unparsed messages, yield those too
    433         while not self._complete:
--> 434             message = self._parse_message()
    435             if message and should_yield(message):
    436                 yield message.as_dict() if as_dict else message

~/opt/anaconda3/envs/body/lib/python3.8/site-packages/fitparse/base.py in _parse_message(self)
    154                     add_dev_data_id(message)
    155                 elif message.mesg_type.name == 'field_description':
--> 156                     add_dev_field_description(message)
    157 
    158         self._messages.append(message)

~/opt/anaconda3/envs/body/lib/python3.8/site-packages/fitparse/records.py in add_dev_field_description(message)
    455     #     units = units.raw_value
    456     # original below
--> 457     units = message.get('units').raw_value
    458 
    459     native_field_num = message.get('native_field_num')

AttributeError: 'NoneType' object has no attribute 'raw_value'

As a potential solution I tried modifying add_dev_field_description to see if units is in the message (see below), and it seemed to resolve the issue:

global DEV_TYPES
dev_data_index = message.get('developer_data_index').raw_value
field_def_num = message.get('field_definition_number').raw_value
base_type_id = message.get('fit_base_type_id').raw_value
field_name = message.get('field_name').raw_value
# starting changes...
units = message.get('units')
if units is not None:
    units = units.raw_value
# ending changes; original below
# units = message.get('units').raw_value
...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions