| Graham Dumpleton (JIRA) 2005-04-30, 2:45 am |
| 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 =20
Versions: 3.1.4 =20
Reporter: Graham Dumpleton
Priority: Minor
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/...ril/XXXXX3.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"=20
Traceback (most recent call last):=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 29=
9, in=20
HandlerDispatch=20
=A0=A0=A0=A0result =3D object(req)=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 297, =
in=20
handler=20
=A0=A0=A0=A0p.run()=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 191, =
in run=20
=A0=A0=A0=A0session =3D Session.Session(req)=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 3=
89, in=20
Session=20
=A0=A0=A0=A0timeout=3Dtimeout, lock=3Dlock)=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 2=
94, in=20
__init__=20
=A0=A0=A0=A0timeout=3Dtimeout, lock=3Dlock)=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 1=
32, in=20
__init__=20
=A0=A0=A0=A0Cookie.add_cookie(self._req, self.make_cookie())=20
=A0=A0File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 1=
60, in=20
make_cookie=20
=A0=A0=A0=A0c.path =3D dirpath[len(docroot):]=20
TypeError: unsubscriptable object=20
This is ultimately caused by code in BaseSession.make_cookie() which reads:
def make_cookie(self):
if self._secret:
c =3D Cookie.SignedCookie(COOKIE_NAME, self._sid,
secret=3Dself._secret)
else:
c =3D Cookie.Cookie(COOKIE_NAME, self._sid)
config =3D self._req.get_options()
if config.has_key("ApplicationPath"):
c.path =3D config["ApplicationPath"]
else:
docroot =3D self._req.document_root()
# the path where *Handler directive was specified
dirpath =3D self._req.hlist.directory=20
c.path =3D 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 =3D '/'
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 =3D self._req.hlist.directory=20
if dirpath:
docroot =3D self._req.document_root()
c.path =3D dirpath[len(docroot):]
else:
c.path =3D'/'
# 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 =3D '/'
This would eliminate the problem altogether and avoid user having to
use workaround of setting ApplicationPath option.
--=20
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secur...nistrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
|