Skip to content

Instantly share code, notes, and snippets.

@jasonbot
Created December 13, 2019 19:09
Show Gist options
  • Save jasonbot/a42d5e9488dce81400e85a2396db2aca to your computer and use it in GitHub Desktop.
Save jasonbot/a42d5e9488dce81400e85a2396db2aca to your computer and use it in GitHub Desktop.
import urllib.parse
def order_query_string(url):
parsed_url = list(urllib.parse.urlparse(url))
# Put the query string params in determinisitic order.
# According to docs.python this is in [3], but docs.python is a liar.
parsed_url[4] = urllib.parse.urlencode(sorted(urllib.parse.parse_qsl(parsed_url[4])))
return urllib.parse.urlunparse(parsed_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment