mido: IOError('data byte must be in range 0..127') with Lakh MIDI file

I can open this attached MIDI file in timidity and Ardour without issue, but mido is unable to parse it. What’s special about it?

E.g.

from mido import MidiFile
MidiFile('0b0812979e33c132046d24575ff810cf.mid')

results in

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-51ef249dd91a> in <module>()
----> 1 MidiFile('0b0812979e33c132046d24575ff810cf.mid')

/home/carl/anaconda3/lib/python3.5/site-packages/mido/midifiles.py in __init__(self, filename, file, type, ticks_per_beat, charset)
    229         elif self.filename is not None:
    230             with io.open(filename, 'rb') as file:
--> 231                 self._load(file)
    232 
    233     def add_track(self, name=None):

/home/carl/anaconda3/lib/python3.5/site-packages/mido/midifiles.py in _load(self, file)
    266 
    267             for i in range(number_of_tracks):
--> 268                 self.tracks.append(self._read_track())
    269                 # Todo: used to ignore EOFError. I hope things still work.
    270 

/home/carl/anaconda3/lib/python3.5/site-packages/mido/midifiles.py in _read_track(self)
    351                 message = self._read_sysex()
    352             else:
--> 353                 message = self._read_message(status_byte)
    354 
    355             message.time = delta

/home/carl/anaconda3/lib/python3.5/site-packages/mido/midifiles.py in _read_message(self, status_byte)
    286         for byte in data_bytes:
    287             if byte > 127:
--> 288                 raise IOError('data byte must be in range 0..127')
    289         return build_message(spec, [status_byte] + data_bytes)
    290 

OSError: data byte must be in range 0..127
pip show mido

---
Metadata-Version: 2.0
Name: mido
Version: 1.1.17
Summary: MIDI Objects for Python
Home-page: https://mido.readthedocs.io/
Author: Ole Martin Bjorndalen
Author-email: ombdalen@gmail.com
Installer: pip
License: MIT
Location: /home/carl/anaconda3/lib/python3.5/site-packages
Requires: 
Classifiers:
  Development Status :: 5 - Production/Stable
  Intended Audience :: Developers
  Natural Language :: English
  License :: OSI Approved :: MIT License
  Programming Language :: Python
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3.2

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 55 (29 by maintainers)

Commits related to this issue

Most upvoted comments

How about this?

mid = MidiFile('test.mid', errors='ignore')

That would make it easy to add more modes like ‘warn’, ‘log’ etc.

Raising a custom exception like MidiParserWarning is a good idea. Today it can fail with all kinds of exceptions making them hard to catch. Maybe that should be the default mode?