Fix Python 3 by handling StringIO

Fixes GH-20