Foros del Web » Programando para Internet » Python »

Problemas con mod_python 3.3.1

Estas en el tema de Problemas con mod_python 3.3.1 en el foro de Python en Foros del Web. Hola estoy migrando de mod_python 3.2.10 a 3.3.1 He hecho un ejemplo sencillo que funciona correctamente en el 3.2.10 pero en el 3.3.1 da error. ...
  #1 (permalink)  
Antiguo 25/11/2009, 07:54
 
Fecha de Ingreso: mayo-2007
Mensajes: 4
Antigüedad: 17 años
Puntos: 0
Problemas con mod_python 3.3.1

Hola estoy migrando de mod_python 3.2.10 a 3.3.1
He hecho un ejemplo sencillo que funciona correctamente en el 3.2.10 pero en el 3.3.1 da error.
¿Alguien me puede ayudar?

Tengo este archivo:
index_prueba.py
Código:
from mod_python import apache, Session, util

def handler(req):

    # pongo el tiempo de session y el tipo de contenido que voy a devolver
    req.content_type = 'text/html'
    
    
    session = Session.Session(req)
    
    if session.is_new():
        obj = Algo()
        session['vamos'] = obj

    fin = session['vamos'].getVar1()
    req.write(fin)
    
    req.write(str(dir(session)))
    req.write(str(session._dbmfile)) 
    
    
    session.save()
    # retorno OK para que devuelva lo impreso
    return apache.OK

class Algo:
    
    var1 = ""
    
    def __init__(self):
        self.var1 = "holaaaa"
    
    def getVar1(self):
        return self.var1
La configuracion de apache:

Código:
AddHandler mod_python .py
PythonHandler index_prueba
PythonDebug On
PythonAutoReload On
Da el siguiente error:

Código:
MOD_PYTHON ERROR

ProcessId:      14820
Interpreter:    'pruebamodpython.lasal'

ServerName:     'pruebamodpython.lasal'
DocumentRoot:   '/home/lasal/domains/pruebamodpython.lasal/httpdocs'

URI:            '/web/index_prueba.py'
Location:       None
Directory:      '/home/lasal/domains/pruebamodpython.lasal/httpdocs/web/'
Filename:       '/home/lasal/domains/pruebamodpython.lasal/httpdocs/web/index_prueba.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'index_prueba'

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target
    result = object(arg)

  File "/home/lasal/domains/pruebamodpython.lasal/httpdocs/web/index_prueba.py", line 11, in handler
    session = Session.Session(req)

  File "/usr/lib/python2.5/site-packages/mod_python/Session.py", line 803, in Session
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.5/site-packages/mod_python/Session.py", line 372, in __init__
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.5/site-packages/mod_python/Session.py", line 180, in __init__
    if self.load():

  File "/usr/lib/python2.5/site-packages/mod_python/Session.py", line 250, in load
    dict = self.do_load()

  File "/usr/lib/python2.5/site-packages/mod_python/Session.py", line 396, in do_load
    return cPickle.loads(dbm[self._sid])

ImportError: No module named _mp_2ae25f84f8e61ef39ed462f7b0d0b622


MODULE CACHE DETAILS

Accessed:       Wed Nov 25 14:57:09 2009
Generation:     1

_mp_2ae25f84f8e61ef39ed462f7b0d0b622 {
  FileName:     '/home/lasal/domains/pruebamodpython.lasal/httpdocs/web/index_prueba.py'
  Instance:     1
  Generation:   1
  Modified:     Wed Nov 25 13:37:41 2009
  Imported:     Wed Nov 25 14:57:08 2009
}

Última edición por titorober; 26/11/2009 a las 01:39
  #2 (permalink)  
Antiguo 25/11/2009, 09:15
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problemas con mod_python 3.3.1

No uso mod_python, pero por aquí encontré un problema similar al tuyo
http://www.modpython.org/pipermail/m...ly/025434.html
http://www.modpython.org/pipermail/m...ly/025435.html
http://www.modpython.org/pipermail/m...ly/025438.html

http://www.dscpl.com.au/wiki/ModPyth...SessionObjects


Saludos.
  #3 (permalink)  
Antiguo 26/11/2009, 01:39
 
Fecha de Ingreso: mayo-2007
Mensajes: 4
Antigüedad: 17 años
Puntos: 0
Respuesta: Problemas con mod_python 3.3.1

si, pero ahí pone que no se puede hacer.
por lo menos yo entiendo eso, no?
  #4 (permalink)  
Antiguo 26/11/2009, 08:34
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problemas con mod_python 3.3.1

Lo que dice es
Cita:
In practice what this means is that neither function objects, class objects or instances of classes should be stored in session objects, unless you are absolutely gauranteed that the module that the original function object or class object resides in was imported using the standard import statement and that it mapped through to the standard Python import mechanism, with the module always residing in sys.modules and never being reloaded.

In order to ensure that no strange problems at all are likely to occur, it is suggested that only basic builtin Python types, ie., scalars, tuples, lists and dictionaries, be stored in session objects. That is, avoid any type of object which has user defined code associated with it.
Recomienda no almacenar en los objetos de sesión ningún objeto que no sea un tipo básico de Python (lista, diccionario, número, cadena), y en el artículo explica un poco el por qué.
Tiene que ver con que, debido a restricciones del módulo pickle, algunas cosas tuvieron que cambiar en mod_python. También menciona por ahí que hay algunos cambios entre las versiones 2.2.x y 2.3.x (aunque no especifica más allá de una mención genérica)

No sé muy bien cuál será la mejor opción, dado que como te mencionaba antes, nunca trabajé con mod_python. Pero se me ocurre que quizás puedas, por ejemplo, convertir el objeto a un diccionario antes de almacenarlo en la sesión.


Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:17.