[mod_python] ValueError with Flash 8 FileReference.upload(url)

Graham Dumpleton grahamd at dscpl.com.au
Wed Apr 5 05:58:30 EDT 2006


Sending the swf file as you did in other email isn't probably of any  
use.
We need to get what is actually received by the handler itself so we
can send that through the util.FieldStorage class to test it. This is  
what
the handler I sent below was about. Note though the small change I
marked against the code below. Don't forget to change the save path to
something meaningful.

Put the code in a file called grabinput.py in your directory:

   c:/Program Files/Apache Group/Apache2/htdocs/python

and change:

   PythonHandler mod_python.publisher

to:

   PythonHandler grabinput

in your config.

It is the file that the upload data is saved into that we would need not
the original swf file.

Graham

On 05/04/2006, at 4:58 PM, Graham Dumpleton wrote:

> Harold J. Ship wrote ..
>> Do you want an ethereal dump, or the flash program that generates
>> requests?
>
> Write a basic handler which does something like:
>
> from mod_python import apache
>
> def handler(req):
>
>     data = open("/some/path/post.dat", "w")

This possible should be:

        data = open("/some/path/post.dat", "wb")

Ie., use binary mode to ensure that \r\n sequences are maintained as is.
This may not be an issue on Win32, but might be still good to do it.

>     data.write(req.read())
>     data.close()
>
>     req.content_type = 'text/plain'
>     req.write("Done")
>
>     return apache.OK
>
> Have your post program post to URL that maps to that handler.
>
> This way it captures exactly what was sent in request and what
> util.FieldStorage will consume and people can experiment.
>
> Just make sure any actual data posted is small. Add it as an
> attachment to your mail.
>
> Graham
>
>
>
>> -----Original Message-----
>> From: Graham Dumpleton [mailto:grahamd at dscpl.com.au]
>> Sent: Wednesday, April 05, 2006 8:12 AM
>> To: Harold J. Ship
>> Cc: mod_python at modpython.org
>> Subject: Re: [mod_python] ValueError with Flash 8
>> FileReference.upload(url)
>>
>> Can you supply an example request body which has the actual data  
>> removed
>> but preserves the header lines you mention as being a potential  
>> issue?
>>
>> Thanks.
>>
>> Graham
>>
>> Harold J. Ship wrote ..
>>> Attempting to upload a file using Flash 8 FileReference.upload(url)
>>> causes a ValueError at line 173 of util.py.
>>>
>>> Windows XP
>>> Apache 2.0.54
>>> mod_python 3.2.8
>>>
>>>> From httpd.conf:
>>> <VirtualHost *:8020>
>>>     ServerName python
>>>     DocumentRoot "c:/Program Files/Apache Group/Apache2/htdocs/ 
>>> python"
>>>     <Directory "c:/Program Files/Apache Group/Apache2/htdocs/ 
>>> python">
>>>         AddHandler mod_python .py
>>>         PythonHandler deko_publisher
>>>         PythonDebug Off
>>>         RewriteEngine On
>>>         RewriteRule ^$ ^$ [F]
>>>         RewriteCond %{REQUEST_FILENAME} !-f
>>>         RewriteRule ^(\w+)/(.*)$ $1.py/$2 [QSA,L]
>>>         ErrorDocument 500 "<h2>Application error</h2>Problem with
>>> Python Setup"
>>>     </Directory>
>>> </VirtualHost>
>>>
>>> deko_publisher is my own handler that delegates to
>>> mod_python.publisher
>>>
>>> It seems that the HTTP request has some header lines that aren't of
>>> the form "Name: value" such as file boundaries.
>>>
>>>> From error.log:
>>>
>>> [Mon Apr 03 12:05:40 2006] [INFO] WebPython deko_publisher.py:17  
>>> about
>>
>>> to run uploadFoo [Mon Apr 03 12:05:40 2006] [error] [client  
>>> 127.0.0.1]
>>
>>> PythonHandler
>>> deko_publisher: Traceback (most recent call last):
>>> [Mon Apr 03 12:05:40 2006] [error] [client 127.0.0.1] PythonHandler
>>> deko_publisher:   File
>>> "C:\\Python23\\Lib\\site-packages\\mod_python\\apache.py", line 299,
>> in
>>> HandlerDispatch\n    result = object(req)
>>> [Mon Apr 03 12:05:41 2006] [error] [client 127.0.0.1] PythonHandler
>>> deko_publisher:   File "C:/Program Files/Apache
>>> Group/Apache2/htdocs/python/deko_publisher.py", line 18, in  
>>> handler\n
>>> return apache.handler(req) [Mon Apr 03 12:05:41 2006] [error]  
>>> [client
>>> 127.0.0.1] PythonHandler
>>> deko_publisher:   File
>>> "C:\\Python23\\Lib\\site-packages\\mod_python\\publisher.py", line
>> 213,
>>> in handler\n    published = publish_object(req, object)
>>> [Mon Apr 03 12:05:41 2006] [error] [client 127.0.0.1] PythonHandler
>>> deko_publisher:   File
>>> "C:\\Python23\\Lib\\site-packages\\mod_python\\publisher.py", line
>> 411,
>>> in publish_object\n    req.form = util.FieldStorage(req,
>>> keep_blank_values=1)
>>> [Mon Apr 03 12:05:41 2006] [error] [client 127.0.0.1] PythonHandler
>>> deko_publisher:   File
>>> "C:\\Python23\\Lib\\site-packages\\mod_python\\util.py", line  
>>> 173, in
>>> __init__\n    h, v = line.split(":", 1)
>>> [Mon Apr 03 12:05:41 2006] [error] [client 127.0.0.1] PythonHandler
>>> deko_publisher: ValueError: unpack list of wrong size
>>>
>>> util.py (lines 169-175):
>>>            while line not in ('\r','\r\n'):
>>>                # we read the headers until we reach an empty line
>>>                # NOTE : a single \n would mean the entity is
>>> malformed, but
>>>                # we're tolerating it anyway
>>>                h, v = line.split(":", 1)
>>>                headers.add(h, v)
>>>                h = h.lower()
>>>
>>> proposed change:
>>>            while line not in ('\r','\r\n'):
>>>                # we read the headers until we reach an empty line
>>>                # NOTE : a single \n would mean the entity is
>>> malformed, but
>>>                # we're tolerating it anyway
>>>                try:
>>>                   h, v = line.split(":", 1)
>>>                except ValueError:
>>>                   h, v = "", ""
>>>                headers.add(h, v)
>>>                h = h.lower()
>>>
>>>
>>>
>>> Harold Ship
>>> Giant Steps Networks
>>>
>>> _______________________________________________
>>> Mod_python mailing list
>>> Mod_python at modpython.org
>>> http://mailman.modpython.org/mailman/listinfo/mod_python
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list