Fixed critical bug due to failing isinstance(..., str) in PY2

Issues like this can always occur if we are not controlling the string
type entirely, for example as it's read from file.