Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a python list in the post query?

I want to send some strings in a list in a POST call. eg:

    www.example.com/?post_data = A list of strings

The python code receives the data as a single string (Instead of a list of strings). How do I post it as a list of strings?

like image 256
Mohit Ranka Avatar asked Dec 08 '08 12:12

Mohit Ranka


3 Answers

There's no such thing as a "list of strings" in a URL (or in practically anything in HTTP - if you specify multiple values for the same header, they come out as a single delimited value in most web app frameworks IME). It's just a single string. I suggest you delimit the strings in some way (e.g. comma-separated) and then parse them out again at the other end.

like image 98
Jon Skeet Avatar answered Oct 22 '22 18:10

Jon Skeet


TRY JSON(JavaScript Object Notation) it's available in the python package. Find out here: http://docs.python.org/library/json.html

You can Encode your list to an array represented in JSON and append to the post argument. Later decode it back to list...

like image 34
yrcjaya Avatar answered Oct 22 '22 17:10

yrcjaya


Are you talking about this?

post_data= ",".join( list_of_strings )
like image 38
S.Lott Avatar answered Oct 22 '22 19:10

S.Lott