code: def encodeStringForB64Header(s):
      
      if isinstance(s, six.text_type):
          s = s.encode()
      return base64.encodestring(s).strip().replace(b'\n', b'')
docs: HTTP Headers can't have new lines in them, let's