Skip to content

Instantly share code, notes, and snippets.

@icarrr
Created June 4, 2021 02:41
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 icarrr/f5fe781e023680ad59b7a59aecde9c92 to your computer and use it in GitHub Desktop.
Save icarrr/f5fe781e023680ad59b7a59aecde9c92 to your computer and use it in GitHub Desktop.
#Python Encode & Decode URL

Python

Encode & Decode URL

Python2

$ alias urldecode='python -c "import sys, urllib as ul; \
    print ul.unquote_plus(sys.argv[1])"'

$ alias urlencode='python -c "import sys, urllib as ul; \
    print ul.quote_plus(sys.argv[1])"'

Python3

$ alias urldecode='python3 -c "import sys, urllib.parse as ul; \
    print(ul.unquote_plus(sys.argv[1]))"'

$ alias urlencode='python3 -c "import sys, urllib.parse as ul; \
    print (ul.quote_plus(sys.argv[1]))"'

Example

$ urldecode 'q+werty%3D%2F%3B'
q werty=/;

$ urlencode 'q werty=/;'
q+werty%3D%2F%3B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment