Using `urllib.parse.quote` should do the trick.