Message92343
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(
"""\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<body>
<div>
<form action="http://{0}{1}/upload"
enctype="multipart/form-data" method="post">
<p>
<input type="file" name="file"><br>
<input type="submit" value="Upload">
</p>
</form>
</div>
</body>
</html>\
""".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(
"""\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<body>
<div>
<p>Success</p>
</div>
</body>
</html>\
"""
); |
|
| Date |
User |
Action |
Args |
| 2009-09-07 05:13:36 | loveminix | set | recipients:
+ loveminix |
| 2009-09-07 05:13:34 | loveminix | set | messageid: <1252300414.57.0.638541093466.issue6854@psf.upfronthosting.co.za> |
| 2009-09-07 05:13:31 | loveminix | link | issue6854 messages |
| 2009-09-07 05:13:28 | loveminix | create | |
|