Created
January 16, 2017 10:27
-
-
Save nkentaro/37f25b802e825da7ab3b7f27c0303047 to your computer and use it in GitHub Desktop.
url encode and decode in python3
This file contains hidden or 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
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
The
quote()
function encodes space to%20
. Python also has aquote_plus()
function that encodes space to plus sign (+
). I've written about URL Encoding in python on my website. There is also an online URL Encoder tool.