UnicodeDecodeError when uploading a file and other fields in form don't validate
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
web.py |
New
|
Undecided
|
Unassigned |
Bug Description
I found when I create a form and the form validates correctly the file
passed will upload fine. However if for example the e-mail field doesn't validate I get the
following error:
2010-04-07 14:55:59: (mod_fastcgi.
File "/usr/lib/
return self.handle()
File "/usr/lib/
return self._delegate(fn, self.fvars, args)
File "/usr/lib/
return handle_class(cls)
File "/usr/lib/
return tocall(*args)
File "/var/www/
return render.upload(f)
File "/usr/lib/
return self._base(t(*a, **kw))
File "/usr/lib/
return BaseTemplate.
File "/usr/lib/
return self.t(*a, **kw)
File "templates/
File "/usr/lib/
value = safeunicode(value)
File "/usr/lib/
return obj.decode(
File "/usr/lib/
return codecs.
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 321-322: invalid data
-------
Code snippet:
vpass = form.regexp(
vemail = form.regexp(
upload_form = form.Form(
form.
form.
form.
)
class upload:
def GET(self):
f = upload_form()
return render.upload(f)
def POST(self):
f = upload_form()
if not f.validates():
else:
p = web.input(
I have a similar issue, but no validation is required, just a simple form with one File field:
plugin_form = web.form.Form(
web.form. File('plugin_ file', web.form.notnull),
)
upon uploading a file from this form, this is the error:
Traceback (most recent call last): pymodules/ python2. 6/web/applicati on.py", line 209, in process processors) ) pymodules/ python2. 6/web/applicati on.py", line 537, in processor pymodules/ python2. 6/web/applicati on.py", line 209, in <lambda> processors) ) pymodules/ python2. 6/web/applicati on.py", line 216, in process ror() pymodules/ python2. 6/web/applicati on.py", line 449, in internalerror debugerror( ) pymodules/ python2. 6/web/debugerro r.py", line 299, in debugerror ror(djangoerror ()) pymodules/ python2. 6/web/debugerro r.py", line 289, in djangoerror pymodules/ python2. 6/web/template. py", line 850, in __call__ __call_ _(self, *a, **kw) pymodules/ python2. 6/web/template. py", line 768, in __call__ output( out) pymodules/ python2. 6/web/template. py", line 774, in _join_output pymodules/ python2. 6/web/debugerro r.pyc", line 183, in __template__ pymodules/ python2. 6/web/webapi. py", line 222, in input pymodules/ python2. 6/web/utils. py", line 141, in storify pymodules/ python2. 6/web/utils. py", line 128, in getvalue pymodules/ python2. 6/web/utils. py", line 123, in unicodify pymodules/ python2. 6/web/utils. py", line 231, in safeunicode encoding) python2. 6/encodings/ utf_8.py" , line 16, in decode utf_8_decode( input, errors, True)
File "/usr/lib/
return p(lambda: process(
File "/usr/lib/
return handler()
File "/usr/lib/
return p(lambda: process(
File "/usr/lib/
raise self.internaler
File "/usr/lib/
return debugerror.
File "/usr/lib/
return web._InternalEr
File "/usr/lib/
return t(exception_type, exception_value, frames)
File "/usr/lib/
return BaseTemplate.
File "/usr/lib/
return self._join_
File "/usr/lib/
for name, value in out:
File "/usr/lib/
$if ctx.output or ctx.headers:
File "/usr/lib/
return storify(out, *requireds, **defaults)
File "/usr/lib/
value = getvalue(value)
File "/usr/lib/
return unicodify(x.value)
File "/usr/lib/
if _unicode and isinstance(s, str): return safeunicode(s)
File "/usr/lib/
return obj.decode(
File "/usr/lib/
return codecs.
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 12-13: invalid data
I don't know what it is trying to decode, the uploaded binary data maybe?