handling None type in str encoding