os.path.exists() throws Exception when the file does
not exist instead of returning 0, ONLY when MySQLdb
0.9.x is imported under mod_python. With 0.3.x works
fine (returns 0), as does without MySQLdb at all.
Test code (write into test.py)
import os.path
from mod_python import apache
def handler(request):
os.path.exists("/tmp/aaaa") output = "Worked.\n" request.content_type = "text/plain" request.send_http_header() request.write(output) return apache.OK
In httpd.conf (besides loading mod_python):
AddHandler python-program .test
PythonHandler test
If I catch the exception it says:
[Errno 2] No such file or directory: '/tmp/aaaa'
Environment is Linux RH 7.1 with
python2-2.1-4 (RPM)
apache 1.3.20
mod_python 2.7.5
One last thing: I straced the httpd and it does this.
I'm guessing that the errors got mixed up somehow but
can't see why or how:
stat64("/var/tmp/python2-2.1-root/usr/lib/python2.1/posixpath.py",
0xbfffe800) = -1 ENOENT (No such file or directory)
It does not do this when MySQLdb is not loaded or if
the path exists.
Logged In: NO
Okay it seems it is not a MySQLdb bug although for some
reason MySQLdb triggers it:
http://www.modpython.org/FAQ/faqw.py?req=all#2.3
I guess this bug can be closed then...
Logged In: YES
user_id=33470
I have noticed that when _mysql_exceptions.py is loaded
from within mod_python it causes python from then on to
behave erratically. This is only with the 0.9.x releases
and not with the 0.3 release.
I have worked around this by removing the "import
Exceptions" line at the top and "del ....." line at the
bottom of _mysql_exceptions.py. I don't know why this is
but it's definitley in the combination of mod_pyhton 2.7.x
and MySQL-python 0.9.x.