Skip to content

Instantly share code, notes, and snippets.

@trim21
Last active July 14, 2023 12:07
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 trim21/b60d3999bea03bcac403380d4b157a02 to your computer and use it in GitHub Desktop.
Save trim21/b60d3999bea03bcac403380d4b157a02 to your computer and use it in GitHub Desktop.
from urllib.parse import parse_qs, quote, unquote_to_bytes, urlparse
raw_bytes = bytes.fromhex('123456789abcdef123456789abcdef123456789a')
url = f'https://example.com/?q={quote(raw_bytes)}'
print(url)
assert unquote_to_bytes(quote(raw_bytes)) == raw_bytes
parsed_q = parse_qs(urlparse(url).query).get("q")[0].encode()
print(parsed_q.hex()) # 12345678efbfbdefbfbdefbfbdefbfbd234567efbfbdefbfbdefbfbdefbfbd12345678efbfbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment