python - Do form parameter names need to be encoded when doing a POST? -


quick version: names of parameters of "forms" being sent using standard multipart/form-data encoding need encoded?

longer version: upload form on 1fichier.com (a service upload large files) uses following specify file parameter upload:

<input type="file" name="file[]" size="50" title="select files upload" /> 

the name of parameter file[] (notice brackets).

using livehttpheaders see parameter sent (i.e. brackets) when submitting form in firefox. however, program i'm writing in python, using poster module able upload files using standard multipart/form-data encoding. if enter parameter name brackets, gets sent this:

file%5b%5d 

internally, poster encodes names of parameters using function:

def encode_and_quote(data):     """if ``data`` unicode, return urllib.quote_plus(data.encode("utf-8"))     otherwise return urllib.quote_plus(data)"""     if data none:         return none      if isinstance(data, unicode):         data = data.encode("utf-8")     return urllib.quote_plus(data) 

the urllib.quote_plus documentation says "required quoting html form values when building query string go url". here we're doing post, form values don't go in url.

so, still need encoded, or error of poster doing this?

rfc 2388 covers multipart/form-data submissions. section 3 specifies parameter names should either ascii or encoded per rfc 2047.

so if post request encoded multipart/form-data (which poster doing), no, parameter names don't need encoded way. suggest filing bug author (ahem...), might willing fix in future release ;)

a workaround set multipartparam's name attribute directly, e.g.

   p.name = 'file[]' 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -