[issue6852] Unicode IO not working in cgi applet

2009-09-06 Thread loveminix

New submission from loveminix :

The following cgi applet does output Unicode string correctly in an
Ubuntu terminal, but when invoked from a web browser (IE or Firefox) by
a client, it doesn't output the Unicode string. Output stops at
"...", right before the Unicode string "中文".

#! /usr/bin/python3
# -*- coding: utf-8 -*-

print(
"""\
Content-type: text/html
"""
);

print(
"""\
http://www.w3.org/TR/html4/strict.dtd";>




\
"""
);

print("");
print("中文");
print("");

print(
"""\

\
"""
);

--
components: Unicode
messages: 92341
nosy: loveminix
severity: normal
status: open
title: Unicode IO not working in cgi applet
type: behavior
versions: Python 3.1

___
Python tracker 
<http://bugs.python.org/issue6852>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6854] UnicodeDecodeError when retrieving binary data from cgi.FieldStorage()

2009-09-06 Thread loveminix

New submission from loveminix :

The following cgi applet uploads a binary file to the server. It gets a
"UnicodeDecodeError" inside cgi.FieldStorage(). The same code works in
python 2.6.

#! /usr/bin/python3

import os, cgi;
import cgitb; cgitb.enable();

pathInfo = os.environ.get("PATH_INFO", "");
serverName = os.environ.get("SERVER_NAME", "");
scriptName = os.environ.get("SCRIPT_NAME", "");

if pathInfo == "":
print(
"""\
Content-type: text/html
"""
);
print(
"""\
http://www.w3.org/TR/html4/strict.dtd";>






http://{0}{1}/upload";
enctype="multipart/form-data" method="post">







\
""".format(serverName, scriptName)
);
elif pathInfo == "/upload":
fieldStorage = cgi.FieldStorage();
fileItem = fieldStorage["file"];
if fileItem.filename != "":
file = open("/tmp/test.txt", mode="wb");
file.write(fileItem.file.read());
file.close();
print(
"""\
Content-type: text/html
"""
);
print(
"""\
http://www.w3.org/TR/html4/strict.dtd";>






Success


\
"""
);

--
components: Library (Lib)
messages: 92343
nosy: loveminix
severity: normal
status: open
title: UnicodeDecodeError when retrieving binary data from cgi.FieldStorage()
type: behavior
versions: Python 3.1

___
Python tracker 
<http://bugs.python.org/issue6854>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6854] UnicodeDecodeError when retrieving binary data from cgi.FieldStorage()

2009-09-07 Thread loveminix

loveminix  added the comment:

Here is the trackback (the uploaded file is a PDF file):

UnicodeDecodeError Python 3.1.1: /home/chu7/software/bin/python3
Mon Sep 7 12:31:07 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.

 /home/chu7/web/cgi-bin/upload.py in () 
 35 );
 
 36 elif pathInfo == "/upload":
 
=>   37 fieldStorage = cgi.FieldStorage();
 
 38 fileItem = fieldStorage["file"];
 
 39 if fileItem.filename != "":
 
fieldStorage undefined, cgi = , cgi.FieldStorage = 
 
 /home/chu7/software/lib/python3.1/cgi.py in __init__(self=FieldStorage
(None, None, []), fp=None, headers={'content-length': '76784', 'content-
type': 'multipart/form-data; boundary=---
7d95563062a'}, outerboundary='', environ=, keep_blank_values=0, strict_parsing=0) 
489 self.read_urlencoded()
 
490 elif ctype[:10] == 'multipart/':
 
=>  491 self.read_multi(environ, keep_blank_values, 
strict_parsing)
 
492 else:
 
493 self.read_single()
 
self = FieldStorage(None, None, []), self.read_multi = , environ = 
, keep_blank_values = 0, 
strict_parsing = 0 
 /home/chu7/software/lib/python3.1/cgi.py in read_multi
(self=FieldStorage(None, None, []), environ=, keep_blank_values=0, strict_parsing=0) 
609 # Create bogus content-type header for proper multipart 
parsing
 
610 parser.feed('Content-Type: %s; boundary=%s\r\n\r\n' % 
(self.type, ib))
 
=>  611 parser.feed(self.fp.read())
 
612 full_msg = parser.close()
 
613 # Get subparts
 
parser = , parser.feed 
= >, self = FieldStorage(None, None, []), self.fp = 
<_io.TextIOWrapper name='' encoding='ANSI_X3.4-1968'>, 
self.fp.read =  
 /home/chu7/software/lib/python3.1/encodings/ascii.py in decode
(self=, 
input=b'-7d95563062a\r\nCo...\n-
7d95563062a--\r\n', final=True) 
 24 class IncrementalDecoder(codecs.IncrementalDecoder):
 
 25 def decode(self, input, final=False):
 
=>   26 return codecs.ascii_decode(input, self.errors)[0]
 
 27 
 
 28 class StreamWriter(Codec,codecs.StreamWriter):
 
global codecs = , 
codecs.ascii_decode = , input = b'--
---7d95563062a\r\nCo...\n---
--7d95563062a--\r\n', self = , self.errors = 'strict' 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 
158: ordinal not in range(128) 
  args = ('ascii', b'-
7d95563062a\r\nCo...\n-7d95563062a--\r\n', 
158, 159, 'ordinal not in range(128)') 
  encoding = 'ascii' 
  end = 159 
  object = b'-7d95563062a\r\nCo...\n
-7d95563062a--\r\n' 
  reason = 'ordinal not in range(128)' 
  start = 158 
  with_traceback = 

--

___
Python tracker 
<http://bugs.python.org/issue6854>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6854] UnicodeDecodeError when retrieving binary data from cgi.FieldStorage()

2009-09-09 Thread loveminix

loveminix  added the comment:

Is there an update on this? Let me know if more information is needed.

--

___
Python tracker 
<http://bugs.python.org/issue6854>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com