Fix base64 encoding on bytes issue in Py3

No immediate regression visible on Py2
Added regression tests as well
Fixes #2553