FitHeaderError: Invalid .FIT File Header
dks7inc opened this issue · comments
Hi
When I an parsing fit files which are stored in the database I got this error FitHeaderError: Invalid.FIT File Header only for one fit file, I am able to parse the remaining fit files
Well, some devices produce FITs with invalid header. Just pass a param FitFile(..., check_crc=False)
. (Note: the official FIT SDK also does not throw error in case of a wrong FIT header.).
hi xmedeko
thanks for your response I added check_crc=False to my code i got same error, I will paste my Traceback
FitHeaderError:
Traceback (most recent call last)
<ipython-input-17-d0c824f75967> in <module>()
3 for x in a1:
4 y = x.fit_file
----> 5 fitfile = FitFile(y,check_crc=False)
6 for record in fitfile.get_messages('record'):
7 for record_data in record:
/app/.heroku/python/lib/python3.6/site-packages/fitparse/base.py in __init__(self, fileish, check_crc, data_processor)
44
45 # Start off by parsing the file header (sets initial attribute values)
---> 46 self._parse_file_header()
47
48 def __del__(self):
/app/.heroku/python/lib/python3.6/site-packages/fitparse/base.py in _parse_file_header(self)
112 header_data = self._read(12)
113 if header_data[8:12] != b'.FIT':
--> 114 raise FitHeaderError("Invalid .FIT File Header")
115
116 # Larger fields are explicitly little endian from SDK
FitHeaderError: Invalid .FIT File Header
Ahh, I see, the problem is not in CRC but in the file structure. Every FIT must have 'FIT' string in the 8th byte. So, it seems your FIT is wrong. (To test the FIT validity you can try the official FIT SDK, or try to import it to the Strava or Garmin Connect.)
thanks xmedeko