Python3 doesn't have long type so isinstance(obj, types.long) will fail. Replacing isinstance(obj, types.long) and isinstance(obj, types.int) with isinstance(obj, six.integer_types)
Also replaced isinstance(obj, str) with isinstance(obj, six.string_types) to handle all string types in python2 and 3.