Use StringIO instead of cStringIO to avoid unicode issues.