Python does not properly process text input from an HTML textarea -


i have standard form on html page usual input types: text, select, submit. using python (the pyramid framework) process these forms has been straightforward , without issue.

in particular form, though, have needed use textarea accept longer, multi-line input. when processing user input in python, i've used following code:

try:     some_input = request.params['form_element'].decode('utf-8') except:     some_input = none 

this works text input, not textarea input. textarea input not processed when unicode character included, , throws following error:

(<type 'exceptions.unicodeencodeerror'>, unicodeencodeerror('ascii', u'some text unicode character \u2013 , more text', 14, 15, 'ordinal not in range(128)'), <traceback object @ 0x10265ca70>) 

is there reason this? looks it's assuming textarea input being treated ascii instead of utf-8, i'm not sure how change this.

more information: page form being submitted html5 page charset set utf-8.

edit: wladimir palant suggested it's been decoded , check this:

print isinstance(request.params['form_element'], str) returns false

print isinstance(request.params['form_element'], unicode) returns true

there no difference between input[type=text] , textarea when data submitted. problem describe should happen in both.

correct me if i'm wrong, webob, used in pyramid, decoding you. unicode already, there no need decode or encode anything. also, can use unicode response, , encoded automatically. have use encode or decode in pyramid applications.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -