File upload gives UnicodeDecodeError

11 views
Skip to first unread message

ambre

unread,
Dec 30, 2008, 2:23:22 PM12/30/08
to web.py
Hi,

I'm using webpy-0.31 and when I try to upload a JPG file, I get this
error (same file upload worked fine with webpy-0.2x).

Traceback (most recent call last):
File "packages/web/application.py", line 211, in process
return self.handle()
File "packages/web/application.py", line 201, in handle
return self._delegate(fn, self.fvars, args)
File "packages/web/application.py", line 385, in _delegate
return handle_class(cls)
File "packages/web/application.py", line 360, in handle_class
return tocall(*args)
File "newsletter.py", line 917, in POST
h.input(web.input())
File "packages/web/webapi.py", line 222, in input
return storify(out, *requireds, **defaults)
File "packages/web/utils.py", line 141, in storify
value = getvalue(value)
File "packages/web/utils.py", line 128, in getvalue
return unicodify(x.value)
File "packages/web/utils.py", line 123, in unicodify
if _unicode and isinstance(s, str): return safeunicode(s)
File "packages/web/utils.py", line 231, in safeunicode
return obj.decode(encoding)
File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0:
unexpected code byte

The error is triggered by calling web.input().

Aaron Swartz

unread,
Dec 30, 2008, 2:24:34 PM12/30/08
to we...@googlegroups.com
file uploads have to be declared like so:

web.input(file={})

ambre

unread,
Dec 30, 2008, 3:02:11 PM12/30/08
to web.py
On Dec 30, 8:24 pm, "Aaron Swartz" <m...@aaronsw.com> wrote:
> file uploads have to be declared like so:
>
> web.input(file={})

Yes I know, and I did it this way.
Here my further investigations:

This works:
f = web.input(datei={})
self.datei = f['datei'].value

Put this gives me the error bellow (here I also use web.input().name:
f = web.input(datei={})
self.datei = f['datei'].value
self.name = web.input().name

My form has not just the file fieled but also at least a name field.

Traceback (most recent call last):
File "packages/web/application.py", line 211, in process
return self.handle()
File "packages/web/application.py", line 201, in handle
return self._delegate(fn, self.fvars, args)
File "packages/web/application.py", line 385, in _delegate
return handle_class(cls)
File "packages/web/application.py", line 360, in handle_class
return tocall(*args)
File "newsletter.py", line 918, in POST
h.input()
File "Header.py", line 52, in input
self.name = web.input().name
File "packages/web/webapi.py", line 222, in input
return storify(out, *requireds, **defaults)
File "packages/web/utils.py", line 141, in storify
value = getvalue(value)
File "packages/web/utils.py", line 128, in getvalue
return unicodify(x.value)
File "packages/web/utils.py", line 123, in unicodify
if _unicode and isinstance(s, str): return safeunicode(s)
File "packages/web/utils.py", line 231, in safeunicode
return obj.decode(encoding)
File "encodings/utf_8.py", line 16, in decode
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0:
unexpected code byte

Erwin

Aaron Swartz

unread,
Dec 30, 2008, 3:06:18 PM12/30/08
to we...@googlegroups.com
> Put this gives me the error bellow (here I also use web.input().name:
> f = web.input(datei={})
> self.datei = f['datei'].value
> self.name = web.input().name

This should be:

self.name = f.name

ambre

unread,
Dec 30, 2008, 3:09:45 PM12/30/08
to web.py
This works!
Many thank's to you and all the developers of webpy!
Reply all
Reply to author
Forward
0 new messages