|
Home > Archive > Apache Mod-Python > March 2006 > mod_python directory index error
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
mod_python directory index error
|
|
| Firat KUCUK 2006-03-21, 7:48 am |
| Hi,
i have a little problem about Directory Index.
this is our .htaccess file:
Allow from All
AddHandler mod_python .py
PythonHandler wepy.handler
PythonDebug On
DirectoryIndex index.htm index.html index.php index.py index.pl
wepy is a new php like web Python library.
http://www.wepy.org/
we just type http://blablabla.com/wepy/
and our main file is index.py
but req.path_info is None
so in mod_python/apache.py/build_cgi_env function:
*if* req.path_info *and* len(req.path_info) > 0:
env[*"SCRIPT_NAME"*] = req.uri[:-len(req.path_info)]
*else*:
env[*"SCRIPT_NAME"*] = req.uri
i think should be like this.
if req.path_info:
env["SCRIPT_NAME"] = req.uri[:-len(req.path_info)]
else:
env["SCRIPT_NAME"] = req.uri
regards
--
*Öğr. Gör. Fırat KÜÇÜK*
Industrial Electronics Program Coordinator
-----------------------------------------------------------
Department of Industrial Electronics
Sakarya University, Adapazari Vocational College
+ 90 (264) 346 02 32, fkucuk[at]sakarya[dot]edu[dot]tr
http://www.adamyo.sakarya.edu.tr/
http://firat.kucuk.org/, firat[at]kucuk[dot]org
-----------------------------------------------------------
| |
| Graham Dumpleton 2006-03-21, 5:48 pm |
| Firat KUCUK wrote ..
> Hi,
>
> i have a little problem about Directory Index.
>
> this is our .htaccess file:
>
> Allow from All
>
> AddHandler mod_python .py
> PythonHandler wepy.handler
> PythonDebug On
>
> DirectoryIndex index.htm index.html index.php index.py index.pl
>
> wepy is a new php like web Python library.
>
> http://www.wepy.org/
>
> we just type http://blablabla.com/wepy/
>
> and our main file is index.py
>
> but req.path_info is None
>
> so in mod_python/apache.py/build_cgi_env function:
>
> *if* req.path_info *and* len(req.path_info) > 0:
> env[*"SCRIPT_NAME"*] = req.uri[:-len(req.path_info)]
> *else*:
> env[*"SCRIPT_NAME"*] = req.uri
>
>
> i think should be like this.
>
> if req.path_info:
> env["SCRIPT_NAME"] = req.uri[:-len(req.path_info)]
> else:
> env["SCRIPT_NAME"] = req.uri
What is the actual problem you are trying to solve?
The "len(req.path_info) > 0" is actually redundant because when
req.path_info is a string and has length 0, the "req.path_info"
boolean check will fail anyway.
In other words, the change you made wouldn't make any difference
that I can see to the actual outcome. Is the redundancy all you
were wanting to point out???
BTW, you should be careful about what SCRIPT_NAME gets set
to by Apache and by this code. See discussion of strange things
that happen at:
https://issues.apache.org/jira/browse/MODPYTHON-68
Graham
| |
| Firat KUCUK 2006-03-21, 5:48 pm |
| Graham Dumpleton yazmış:
>Firat KUCUK wrote ..
>
>
>
>What is the actual problem you are trying to solve?
>
>The "len(req.path_info) > 0" is actually redundant because when
>req.path_info is a string and has length 0, the "req.path_info"
>boolean check will fail anyway.
>
>In other words, the change you made wouldn't make any difference
>that I can see to the actual outcome. Is the redundancy all you
>were wanting to point out???
>
>BTW, you should be careful about what SCRIPT_NAME gets set
>to by Apache and by this code. See discussion of strange things
>that happen at:
>
> https://issues.apache.org/jira/browse/MODPYTHON-68
>
>Graham
>
>
>
>
briefly:
print len(None)
TypeError: len() of unsized object
if we use:
if req.path_info *and* len(req.path_info) > 0:
the same error will be occur.
please try
DirectoryIndex index.py
and use cgihandler.
req.path_info will be None.
and we cannot calculate length of none object
--
*Öğr. Gör. Fırat KÜÇÜK*
Industrial Electronics Program Coordinator
-----------------------------------------------------------
Department of Industrial Electronics
Sakarya University, Adapazari Vocational College
+ 90 (264) 346 02 32, fkucuk[at]sakarya[dot]edu[dot]tr
http://www.adamyo.sakarya.edu.tr/
http://firat.kucuk.org/, firat[at]kucuk[dot]org
-----------------------------------------------------------
| |
| Graham Dumpleton 2006-03-21, 5:48 pm |
| Firat KUCUK wrote ..
> Graham Dumpleton yazmış:
>
> briefly:
>
> print len(None)
>
> TypeError: len() of unsized object
>
>
> if we use:
>
> if req.path_info *and* len(req.path_info) > 0:
>
> the same error will be occur.
>
> please try
> DirectoryIndex index.py
> and use cgihandler.
>
> req.path_info will be None.
> and we cannot calculate length of none object
If req.path_info is None, the RHS of the "and" is not executed
so len() is never performed on a None object.
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.[vbcol=seagreen]
... print "hi"
...[vbcol=seagreen]
... print "hi"
...[vbcol=seagreen]
I really can't see how this can be a source of a problem.
I had already written a separate test handler to check.
AddHandler mod_python .py
PythonHandler index
PythonDebug On
DirectoryIndex index.py
# ---
from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.write("%s\n"%req.path_info)
req.write("%s\n"%apache.build_cgi_env(req))
return apache.OK
Output shows:
None
{......, 'SCRIPT_NAME': '/~grahamd/script_name/index.py', 'REQUEST_URI': '/~grahamd/script_name/', ......}
No error occurred.
If you are getting an actual error of some sort, then post what
the full traceback is, as at the moment this isn't making a great
deal of sense to me.
Graham
| |
| Jim Gallacher 2006-03-21, 5:48 pm |
| Firat KUCUK wrote:
> Graham Dumpleton yazmış:
>
> briefly:
>
> print len(None)
>
> TypeError: len() of unsized object
>
>
> if we use:
>
> if req.path_info *and* len(req.path_info) > 0:
>
> the same error will be occur.
Not in my Python it doesn't.
Python 2.3.5 (#2, Nov 20 2005, 16:40:39)
[GCC 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.[vbcol=seagreen]
.... print True
.... else:
.... print False
....
False[vbcol=seagreen]
Perhaps you could show us the full traceback?
Jim
| |
| Firat KUCUK 2006-03-21, 5:48 pm |
|
i think this is an old version problem:
ubuntu breezy default version is: 4.3.9-2
The code is not the same as at the svn.
Mod_python error: "PythonHandler wepy.handler"
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.4/site-packages/wepy/handler.py", line 20, in handler
env, si, so = apache.setup_cgi(req)
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 706, in setup_cgi
os.environ.update(build_cgi_env(req))
File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 541, in build_cgi_env
if len(req.path_info) > 0:
TypeError: len() of unsized object
i found the fixed revision:
http://svn.apache.org/viewcvs.cgi?rev=104092&view=rev
Added a check for path_info so that we don't try to get len() of None.
my mistake,
thanks for your support.
--
*Öğr. Gör. Fırat KÜÇÜK*
Industrial Electronics Program Coordinator
-----------------------------------------------------------
Department of Industrial Electronics
Sakarya University, Adapazari Vocational College
+ 90 (264) 346 02 32, fkucuk[at]sakarya[dot]edu[dot]tr
http://www.adamyo.sakarya.edu.tr/
http://firat.kucuk.org/, firat[at]kucuk[dot]org
-----------------------------------------------------------
|
|
|
|
|