[mod_python] in modpython ,how to restrict the upload file size?

Clodoaldo clodoaldo.pinto.neto at gmail.com
Wed Jan 31 12:10:59 EST 2007

Jorey Bump Wed Sep 20 08:18:40 EDT 2006
>yjfuk wrote:
>> in modpython ,how to restrict the upload file size?

>I prefer to do this in the apache config, so it applies to all applications:

># limit size of uploads
># 3MB
>LimitRequestBody 3072000

I'm using modpython 3.3 and publisher.

I'm trying to use the LimitRequestBody directive and it works to
prevent the uploding of big files.

The problem I'm having is that although an error is logged by Apache,
a 200 response is sent to the browser. It looks like my publisher
module is not called after Apache catches the file upload error or it
is called and somehow a 20 bytes body is sent with a 200 code. I can't
see those 20 bytes in the browser, the html source is blank.

I would like my publisher module to be called so I can handle the
error and send an appropriate page to the client. Is it possible with
the publisher?

[Wed Jan 31 15:59:47 2007] [error] [client] Requested
content-length of 1482946 is larger than the configured limit of
50000, referer: http://carroarodo.s0/upload_fotos - - [31/Jan/2007:15:59:47 +0000] "POST /upload_fotos
HTTP/1.1" 200 20 "http://carroarodo.s0/upload_fotos" "Mozilla/5.0
(X11; U; Linux i686; en-US; rv: Gecko/20061221
Fedora/ Firefox/"

    ServerName carroarodo.s0
    ServerAdmin admin at carroarodo.com
    DocumentRoot /var/www/html/carroarodo.com
    ErrorLog logs/carroarodo.s0-error_log
    CustomLog logs/carroarodo.s0-access_log combined
    LimitRequestBody 50000
    PythonDebug On
    <Directory /var/www/html/carroarodo.com>
       SetHandler mod_python
       PythonHandler ~/_publisher.py
       PythonOption mod_python.importer.path "['~/mod']"
    <Directory /var/www/html/carroarodo.com/mod>
       Order Allow,Deny
       Deny from all
    <Directory /var/www/html/carroarodo.com/pub/fotos>
       ExpiresActive On
       ExpiresDefault "access plus 0 hours"
    Options -Indexes
    <Files ~ "\.(gif|jpg|png|css|js)$">
       SetHandler default-handler

$ cat _publisher.py
from mod_python import publisher

def handler(req):
   return publisher.handler(req)

Clodoaldo Pinto Neto

More information about the Mod_python mailing list