Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Forked from nkentaro/urlcodec.py
Created July 2, 2018 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brun0xff/cfa1687779f6d9d9abcb7a16696b33d2 to your computer and use it in GitHub Desktop.
Save brun0xff/cfa1687779f6d9d9abcb7a16696b33d2 to your computer and use it in GitHub Desktop.
url encode and decode in python3
import urllib.parse
def urlencode(str):
return urllib.parse.quote(str)
def urldecode(str):
return urllib.parse.unquote(str)
str = '{"name": "Kinkin"}'
encoded = urlencode(str)
print(encoded) # '%7B%22name%22%3A%20%22Kinkin%22%7D'
decoded = urldecode(encoded)
print(decoded) # '{"name": "Kinkin"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment