Python doesn't seem to have a function to do this - or documentation that an existing function can do this - and I am a bit lost combing through RFCs.
I have a url that I have parsed with urlparse:
url = "https://example.com/path/to;jsessionid=foo?foo=bar&biz=bang"
It has both "params" and a "query string"
I need to decode/recode the params (jsessionid=foo)
For decoding, I tried urlparse.parse_qs
and it works fine. Looking at the code, it appears to use ;
as primary delimiter in a nested list comprehension:
def parse_qsl(qs
...
pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
In terms of rebuilding the params though, it seems that I'd need to re-implement urllib.urlencode
and just change the delimiter from &
to ;
.
That seems a bit odd to me, and I feel like I must be missing something obvious.
edit: After thinking, I could probably just do params = params.replace("&", ";")
as the key/value payloads shouldn't be affected since the RFC has both characters reserved.