Skip to content

Instantly share code, notes, and snippets.

@raeq
Created July 19, 2020 12:50
Show Gist options
  • Save raeq/7c2d6e426057928684b10fa260718aae to your computer and use it in GitHub Desktop.
Save raeq/7c2d6e426057928684b10fa260718aae to your computer and use it in GitHub Desktop.
Encode and decode UTF-8 URL
import urllib.parse
def encode_url(url: str = "") -> str:
return urllib.parse.quote(url)
def decode_url(url: str = "") -> str:
return urllib.parse.unquote(url)
assert (encode_url("example.com?title=¨ˆπœ˚∑π") ==
"example.com%3Ftitle%3D%C2%A8%CB%86%CF%80%C5%93%CB%9A%E2%88%91%CF%80")
assert decode_url("example.com?title=%a0%f7%b1") == "example.com?title=���"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment