[issue4953] cgi module cannot handle POST with multipart/form-data in 3.0

2009-01-16 Thread oopos

oopos  added the comment:

Hehe.
I only want to use python to slove the upload files instead of PHP.but
it is hard to me or I have no much time to leran it.
Now,I learn Perl quickly and use it upload files, it works ok.

Thank you . I will take more time to learn Python language well.
Best Regards!

This is my code: (Perl Language)

Added file: http://bugs.python.org/file12768/opsuper.pl

___
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



[issue4953] Cannot upload binary file from form ?

2009-01-15 Thread oopos

oopos  added the comment:

Thank you for time.
Now,I try with you saied.Bu it is taken wrong as before.

See the files:

Added file: http://bugs.python.org/file12753/full_source_and_error.zip

___
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



[issue4953] Cannot upload binary file from form ?

2009-01-15 Thread oopos

oopos  added the comment:

To Amaury Forgeot d'Arc :

Thank you.

That error have sloved with your way:
[quote]Does it work if you change your script like this:
   opsform = cgi.FieldStorage(open(sys.stdin.fileno(), 'rb'))[/quote]

Now,The new problem come out:
[code]  97 """Push some new data into this object."""
 
   98 # Handle any previous leftovers
 
   99 data, self._partial = self._partial + data, ''
 
  100 # Crack into lines, but preserve the newlines on the end 
of each
 
  101 parts = NLCRE_crack.split(data)
 
data = b'-7d91f41a302f4
\nCo...\x0e\x0f\x0c\x10\x17\x14\x18\x18\x17\x14\x16\x16', self = 
, self._partial 
= '' 

TypeError: Can't convert 'bytes' object to str implicitly 
[/code]

I find that the CGI LIB didn't use bytes flow, it always use string 
flow.

More info in the attch file:

Added file: http://bugs.python.org/file12751/tmpy44zj7.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



[issue4953] Cannot upload binary file from form ?

2009-01-15 Thread oopos

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