[ http://issues.apache.org/jira/browse/MODPYTHON-50?page=all ] Graham Dumpleton closed MODPYTHON-50: -------------------------------------
> Session use outside of <Directory> directive. > --------------------------------------------- > > Key: MODPYTHON-50 > URL: http://issues.apache.org/jira/browse/MODPYTHON-50 > Project: mod_python > Type: Improvement > Components: core > Versions: 3.1.4 > Reporter: Graham Dumpleton > Assignee: Nicolas Lehuen > Priority: Minor > Fix For: 3.2.7 > > MODPYTHON-31 was previously closed with outcome of "Won't Fix". > The orginal problem as described in the report was actually not connected > to the Python traceback which was supplied, but the Python traceback > still identified a problem which shold be fixed. Have logged this separate > report to cover this issue. > The issue again came up recently on the mailing list as: > http://www.modpython.org/pipermail/mod_python/2005-April/017933.html > Specifically, if PythonHandler is specified outside of any <Directory> > directive and sessions are used, you can get the error: > Mod_python error: "PythonHandler mod_python.psp" > Traceback (most recent call last): > File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in > HandlerDispatch > result = object(req) > File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 297, in > handler > p.run() > File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 191, in run > session = Session.Session(req) > File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 389, in > Session > timeout=timeout, lock=lock) > File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 294, in > __init__ > timeout=timeout, lock=lock) > File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 132, in > __init__ > Cookie.add_cookie(self._req, self.make_cookie()) > File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 160, in > make_cookie > c.path = dirpath[len(docroot):] > TypeError: unsubscriptable object > This is ultimately caused by code in BaseSession.make_cookie() which reads: > def make_cookie(self): > if self._secret: > c = Cookie.SignedCookie(COOKIE_NAME, self._sid, > secret=self._secret) > else: > c = Cookie.Cookie(COOKIE_NAME, self._sid) > config = self._req.get_options() > if config.has_key("ApplicationPath"): > c.path = config["ApplicationPath"] > else: > docroot = self._req.document_root() > # the path where *Handler directive was specified > dirpath = self._req.hlist.directory > c.path = dirpath[len(docroot):] > # Sometimes there is no path, e.g. when Location > # is used. When Alias or UserDir are used, then > # the path wouldn't match the URI. In those cases > # just default to '/' > if not c.path or not self._req.uri.startswith(c.path): > c.path = '/' > return c > What happens when PythonHandler is defined outside of a <Directory> > directive is that req.hlist.directory is None, thus indexing into dirpath > fails. > A workaround is to set ApplicationPath option, but true fix would be > to write code something like: > # the path where *Handler directive was specified > dirpath = self._req.hlist.directory > if dirpath: > docroot = self._req.document_root() > c.path = dirpath[len(docroot):] > else: > c.path ='/' > # Sometimes there is no path, e.g. when Location > # is used. When Alias or UserDir are used, then > # the path wouldn't match the URI. In those cases > # just default to '/' > if not c.path or not self._req.uri.startswith(c.path): > c.path = '/' > This would eliminate the problem altogether and avoid user having to > use workaround of setting ApplicationPath option. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira