In case the string contains unicode characters (e.g. emoji text=u'monkey \U0001F435'.encode('utf-8')), str() operation fails.
@amittalmor thanks for the fix! Can you please add a simple unit test with example input that shows the issue? This will make sure that unicode characters continue to work in the future.