[Fixed]-Python urlparse.parse_qs unicode url

17👍

Encode back to bytes before passing it to .parse_qs(), using ASCII:

query_dict = urlparse.parse_qs(query.encode('ASCII'))

This does the same thing as str() but with an explicit encoding. Yes, this is safe, the URL encoding uses ASCII codepoints only.

parse_qs was handed a Unicode value, so it returned you a unicode value too; it is not it’s job to decode bytes.

Leave a comment