Fixed #11892, fixed #16458, fixed #14492.
Should be unneeded with Python 2.7 and up. Added some unicode_literals along the way.