Call safe_encode() instead of str()

To avoid the error in python2.6:
"UnicodeEncodeError: 'ascii' codec can't encode characters",
use safe_encode() to encode basestring instead of str().

Fix bug #1218719

Change-Id: Id26f23ad7f975a3a50750927adbedb86bf80871d
Merge "Call safe_encode() instead of str()"