New submission from oopos :
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
-
Hi,I user Python!
UnicodeDecodeError Python 3.0: G:\cgi\python\python.exe
Thu Jan 15 16:46:34 2009
A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.
G:\webserver\xampp\cgi-bin\testupload.py in ()
107
108 # get form
109 opsform = cgi.FieldStorage()
110
111 print ("","form-data:","",opsform,"")
opsform undefined, cgi = ,
cgi.FieldStorage =
G:\cgi\python\lib\cgi.py in __init__(self=FieldStorage(None, None, []),
fp=None, headers={'content-length': '671631', 'content-type':
'multipart/form-data;
boundary=---9699301019407'}, outerboundary='',
environ=, keep_blank_values=0,
strict_parsing=0)
477 self.read_urlencoded()
478 elif ctype[:10] == 'multipart/':
479 self.read_multi(environ, keep_blank_values,
strict_parsing)
480 else:
481 self.read_single()
self = FieldStorage(None, None, []), self.read_multi = , environ =
, keep_blank_values = 0,
strict_parsing = 0
G:\cgi\python\lib\cgi.py in read_multi(self=FieldStorage(None, None,
[]), environ=, keep_blank_values=0,
strict_parsing=0)
597 # Create bogus content-type header for proper multipart
parsing
598 parser.feed('Content-Type: %s; boundary=%s\r\n\r\n' %
(self.type, ib))
599 parser.feed(self.fp.read())
600 full_msg = parser.close()
601 # Get subparts
parser = , parser.feed
= >, self = FieldStorage(None, None, []), self.fp =
, self.fp.read = >
G:\cgi\python\lib\io.py in read(self=, n=-1)
1722 # Read everything.
1723 result = (self._get_decoded_chars() +
1724 decoder.decode(self.buffer.read(), final=True))
1725 self._set_decoded_chars('')
1726 self._snapshot = None
decoder = ,
decoder.decode = , self = , self.buffer
= , self.buffer.read = >,
final undefined
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 157-158:
illegal multibyte sequence
args = ('gbk',
b'-9699301019407\r\n...-9699301019407--\r\n',
157, 159, 'illegal multibyte sequence')
encoding = 'gbk'
end = 159
object =
b'-9699301019407\r\n...-9699301019407--\r\n'
reason = 'illegal multibyte sequence'
start = 157
with_traceback =
l:\tmp_dir\tmpxyeojf.html contains the description of this error.
---
Hi,
I am newbie for python under the windows.
I find that the cgi module always work wrong for the binary files to upload.
I find that it cannot auto to discern the files' mode and alway use the
default mode : 'TEXT'.
So I want to change the sys.stdin 's mode to BINARY to support the
binary files.
I got this way:
import msvcrt,os
msvcrt.setmode(0,os.O_BINARY) # for stdin
msvcrt.setmode(1,os.O_BINARY) # for stdout
but it isn't work,too.
I know use C progam language can use this function:
freopen("somefilename","mode","stdin or stdout") to redirect the file
flow.
Can every one help me ?
Best Regards
oopos
I
--
components: Unicode
files: tmpav1vve.html
messages: 79892
nosy: oopos
severity: normal
status: open
title: Cannot upload binary file from form ?
type: performance
versions: Python 3.0
Added file: http://bugs.python.org/file12750/tmpav1vve.html
___
Python tracker
<http://bugs.python.org/issue4953>
___
___
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com