[mod_python] SystemError: bad argument to internal function

Graham Dumpleton graham.dumpleton at gmail.com
Sat Jun 16 20:08:49 EDT 2007


I think we can rule out parse_qsl() since someone on Django list has
just had same problem but all they are calling is req.read(). See:

  http://groups.google.com/group/django-users/browse_frm/thread/f0159aca7bfbaf57?hl=en

Thus, looks like some subtle bug in req.read() which only very rarely
is triggered.

Graham

On 16/06/07, Clodoaldo <clodoaldo.pinto at gmail.com> wrote:
> 2007/6/15, Graham Dumpleton <graham.dumpleton at gmail.com>:
> > I doubt it would be the image as one shouldn't be using
> > "application/x-www-form-urlencoded" for images. But then that may be
> > part of the problem as posting data with embedded nulls would probably
> > cause parse_qsl() to fail or at least give incorrect results because
> > it uses strlen() on data. Should really be using some form of
> > "multipart" content type for posts of binary data. For example
> > "multipart/mixed" perhaps.
>
> I was wrong. That program handles two pages, only one has a form and
> it is not the images one.
>
> I did set the action of the form to the standard handler as you
> suggested and this is the output:
>
> 664
> application/x-www-form-urlencoded
>
> pagina_servida=True&estado_sigla=SP&localidade=S%C3%A3o+Paulo&bairro=Jardins&fabricante=1&modelo=213&versao=ELX&ano=2007&ano_modelo=2008&preco=200005&motor_volume=1.0&cor=cinza&quilometragem=23000&combustivel=1&remLen=2&texto_chamada=fiesta+sedan+completo%2C+ar+dire%C3%A7ao%2C+vidros%2C+travas%2C+alarme..%2Clindo+sem+retoques+estado+de+novo+%2Cparticular%2Cunico+dono%2Ccomprei+ha+um+ano+no+valor+de+34.500+reiais+e+dei+12.500+de+entrada+e+financiei+o+restante+%2822.000%29+em+60+vezes+de+600+reais%2C+ja+paguei+15+parcelas+e+ainda+restam+45+parcelas.estou+pedindo+pelo+que+ja+paguei+somente+14.500+reais...&mostra_email=1&publicar=1&salvar=Salvar+%2F+Republicar
>
>
> > One final question, is the incoming body of the request being
> > compressed in anyway when being sent by the browser as there are
> > issues in mod_python where an input filter is being applied to
> > incoming content and the content length of data is changed and ends up
> > different to the content length header. I only saw this as resulting
> > in truncated input, but maybe it causes other problems as well.
>
> I make no compression of the submitted body. I don't use any input
> filter, only a DEFLATE output filter.
>
> These are the headers when submitting to the standard handler in the
> test machine:
>
> Response Headers
> Date    Fri, 15 Jun 2007 15:47:05 GMT
> Server  Apache/2.2.4 (Fedora)
> Keep-Alive      timeout=10, max=100
> Connection      Keep-Alive
> Transfer-Encoding       chunked
> Content-Type    text/plain; charset=UTF-8
>
> Request Headers
> Host    teste.s0
> User-Agent      Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4)
> Gecko/20070603 Fedora/2.0.0.4-2.fc7 Firefox/2.0.0.4
> Accept  text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language en-us,en;q=0.5
> Accept-Encoding gzip,deflate
> Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive      300
> Connection      keep-alive
> Referer http://carroarodo.s0/meu_anuncio
>
> And these are the headers when submitting to the normal form handling
> page in the production machine.
>
> Response Headers
> Date    Fri, 15 Jun 2007 15:53:58 GMT
> Server  Apache/2.2.4 (Fedora)
> Vary    Accept-Encoding
> Content-Encoding        gzip
> Content-Length  2018
> Keep-Alive      timeout=15, max=1000
> Connection      Keep-Alive
> Content-Type    text/html; charset=UTF-8
> Content-Language        pt-BR
>
> Request Headers
> Host    carroarodo.com
> User-Agent      Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4)
> Gecko/20070603 Fedora/2.0.0.4-2.fc7 Firefox/2.0.0.4
> Accept  text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> Accept-Language en-us,en;q=0.5
> Accept-Encoding gzip,deflate
> Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive      300
> Connection      keep-alive
> Referer http://carroarodo.com/meu_anuncio
> Cookie  ja_visitou=1180872725.75;
> pysid=b4b28e54a9e77ddbcf47e1ae3dd4454e36b1f09d4b93434121bc6e1c0760d5c0
>
> Clodoaldo
>
> > On 15/06/07, Clodoaldo <clodoaldo.pinto.neto at gmail.com> wrote:
> > > 2007/6/15, Graham Dumpleton <graham.dumpleton at gmail.com>:
> > > > Can you send the same POST content to a standard handler containing:
> > >
> > > The error was triggered by user input I and can't reproduce it. It
> > > happened only twice. To complicate it the same program meu_anuncio.py
> > > handles 2 forms and I don't know which one triggered the error. One of
> > > the forms uploads pictures. I have tested that program extensively and
> > > found no problems. Tried again now in the production machine and I
> > > can't trigger the error.
> > >
> > > In some hours I will post the content of a non error-triggering POST.
> > >
> > > Clodoaldo
> > >
> > > >
> > > >   def handler(req):
> > > >     req.content_type = 'text/plain'
> > > >     print >> req, req.headers_in["content-length"]
> > > >     print >> req, req.headers_in["content-type"]
> > > >     print >> req
> > > >     print >> req, req.read()
> > > >     return apache.OK
> > > >
> > > > Am expecting the content type to be
> > > > "application/x-www-form-urlencoded" which is triggering parse_qsl().
> > > > The intent of the above script is to capture the POST data so you can
> > > > post it and we can then use it as test data for calling parse_qsl()
> > > > direct.
> > > >
> > > > At this point figuring that parse_qsl() has bug.
> > > >
> > > > While you do that I'll look through parse_qsl() code and see if I can
> > > > see any problem.
> > > >
> > > > Graham
> > > >
> > > >
> > > >
> > > > On 15/06/07, Clodoaldo <clodoaldo.pinto.neto at gmail.com> wrote:
> > > > > 2007/6/14, Graham Dumpleton <graham.dumpleton at gmail.com>:
> > > > > > Did you ever sort this out?
> > > > >
> > > > > No
> > > > >
> > > > > > Which sub revision of Python 2.4 are you using? The source code line
> > > > > > numbers don't match up with anything meaningful in Python 2.4.3 source
> > > > > > code that I have on hand.
> > > > >
> > > > > Python 2.4.4 in Fedora Core 6, Apache 2.2.4, mod_python 3.3.1
> > > > >
> > > > > Clodoaldo
> > > > >
> > > > > > On 09/06/07, Clodoaldo <clodoaldo.pinto.neto at gmail.com> wrote:
> > > > > > > I have this in my error log and I don't know what it means or what to do:
> > > > > > >
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] mod_python
> > > > > > > (pid=15022, interpreter='carroarodo.com', phase='PythonHandler',
> > > > > > > handler='~/_publisher.py'): Application error, referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] ServerName:
> > > > > > > 'carroarodo.com', referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]
> > > > > > > DocumentRoot: '/var/www/html/carroarodo.com', referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] URI:
> > > > > > > '/meu_anuncio', referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Location:
> > > > > > > None, referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Directory:
> > > > > > > '/var/www/html/carroarodo.com/', referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Filename:
> > > > > > > '/var/www/html/carroarodo.com/meu_anuncio.py', referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] PathInfo:
> > > > > > > '', referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Traceback
> > > > > > > (most recent call last):, referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/usr/lib64/python2.4/site-packages/mod_python/importer.py", line
> > > > > > > 1537, in HandlerDispatch\n    default=default_handler, arg=req,
> > > > > > > silent=hlist.silent), referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/usr/lib64/python2.4/site-packages/mod_python/importer.py", line
> > > > > > > 1229, in _process_target\n    result = _execute_target(config, req,
> > > > > > > object, arg), referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/usr/lib64/python2.4/site-packages/mod_python/importer.py", line
> > > > > > > 1128, in _execute_target\n    result = object(arg), referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/var/www/html/carroarodo.com/_publisher.py", line 5, in handler\n
> > > > > > > return publisher.handler(req), referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line
> > > > > > > 213, in handler\n    published = publish_object(req, object), referer:
> > > > > > > http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line
> > > > > > > 424, in publish_object\n    req.form = util.FieldStorage(req,
> > > > > > > keep_blank_values=1), referer: http://carroarodo.com/meu_anuncio
> > > > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > > > "/usr/lib64/python2.4/site-packages/mod_python/util.py", line 225, in
> > > > > > > __init__\n    pairs = parse_qsl(req.read(clen), keep_blank_val[Tue Jun
> > > > > > > 05 18:33:49 2007] [error] [client 200.155.85.225] SystemError:
> > > > > > > Objects/stringobject.c:3515: bad argument to internal function,
> > > > > > > referer: http://carroarodo.com/meu_anuncio
> > > > > > >
> > > > > > > Any hints?
> > > > > > >
> > > > > > > Regards, Clodoaldo Pinto Neto
> > > > > >
> > > > >
> > > >
> > >
> >
>


More information about the Mod_python mailing list