def jwt_b64e(string): if isinstance(string, unicode): string = string.encode('utf-8', 'strict') return base64.urlsafe_b64encode(string).strip(b'=')