Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nkentaro
Created January 16, 2017 10:27
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nkentaro/37f25b802e825da7ab3b7f27c0303047 to your computer and use it in GitHub Desktop.
Save nkentaro/37f25b802e825da7ab3b7f27c0303047 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"}'
@callicoder
Copy link

The quote() function encodes space to %20. Python also has a quote_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment