you did not say what error you get, but i can guess it relates to unicode vs bytes.

base64.encode takes a bytes object, you are giving it a string.
try replaceing decoded with decoded.encode('ascii') before passing into base64.b64encode