You should use `basestring` here instead of `str`.  (In Python3, basestring is defined to be str.)