Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Python's urlparse.parse_qs() split arguments on semicolon

I'm writing a test script in Python to check the output of my PHP application and I've got a problem with Python's urlparse.parse_qs() function. GET string delimiter (AFAIK) is an ampersand. The function (as I understand) is supposed to split a GET string into Python dictionary, so that the output for count=2&offset=5&userID=1 should be:

{'count': ['2'], 'userID': ['1'], 'offset': ['5']}

And it is. But when I try to pass CSV in GET (separated with semicolons) such as ids=5;15;3, I get the following:

[('3', ''), ('15', ''), ('ids', '5')]

I think the valid output should look like this:

{'ids': ['5;15;3']}

What am I doing wrong? The line looks like this:

args = urlparse.parse_qs(sys.argv[2], keep_blank_values=True)
like image 498
czesiek Avatar asked Mar 01 '11 18:03

czesiek


1 Answers

';' is equivalent to '&'

W3C recommends that all web servers support semicolon separators in the place of ampersand separators.

So use ',' instead.

like image 178
Kabie Avatar answered Nov 15 '22 12:11

Kabie