Created
August 25, 2017 12:39
-
-
Save khornberg/b87e4a72532a342e1e5ebb16b5739e8f to your computer and use it in GitHub Desktop.
python 3 base64 encode dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a dictionary, transform it to a string. Then byte encode that string. Then base64 encode it and since this will go | |
on a url, use the urlsafe version. Then decode the byte string so that it can be else where. | |
""" | |
data = base64.urlsafe_b64encode(json.dumps({'a': 123}).encode()).decode() | |
# And the decode is just as simple... | |
data = json.loads(base64.urlsafe_b64decode(query_param.encode()).decode()) | |
# Byte encode the string, base64 decode that, then byte decode, finally transform it to a dictionary |
Thanks allot for this, saved me a bit of time
thanks
thank you good sir
Thank you very much!
thanks, this is really helpful
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'it can be (used)? else where`?