![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Cannot open a file with mod_python
My apologies if this should have gone in the web programming forum. Since it pertains to python, I was uncertain.
I'm trying to finish up a small web app that I've been working on (written in python). The gist of it is that it allows me (and my fellow students) to easily track our billing for patients that we have seen. The back end is finished and functional, and I've been working on integrating the web GUI. The problem arises, however, when I move all my files over to my apache directory (/var/www). Once my files are there, the program can't seem to find them. I've tried using the full path (/var/www/data/cptcodes2007), the path relative to the webserver (/data/cptcodes2007), and simply having the files in the same dir as my .py files. The file can be read by browsing (in firefox) to localhost/data/cptcodes, and some independent scripts I wrote to check for mod_python functionality work correctly, so I don't believe that it is an apache configuration issue (though I will readily admit I know very little about apache as of yet). Am I simply trying to look for the file in the wrong place? Am I using os.path.isfile(filename) incorrectly? Relevant code from my test script and the actual routine to read the file posted below. The red section is the error that is being raised. Test script: from mod_python import apache, util, psp
import audiclock
import sha
import os
def index(req):
# The publisher will call this function as default,
req.write('running _get_vars()<br />')
_get_vars(req)
def _get_vars(req):
formData = req.form
req.write('grabbed form data; here is what I am seeing:<br />')
for item in formData.keys():
req.write('%s:\t%s<br />' % (item, formData[item]))
req.write('running _set_page()<br />')
_set_page(req, formData)
def _set_page(req, formData):
audiclock.read_all()
if formData.has_key('currentPage') and formData['currentPage'] == 'process_me':
if formData.has_key('luser') and formData.has_key('lapp') and formData.has_key('lpatient'):
for item in formData.keys():
if item in audiclock.cptCode.keys() and formData['item'] == "on":
audiclock.final_result(formData['lapp'], formData['lpatient'], item, formDatap['luser'])
req.write('Item %s recorded.<br />' % (item))
else:
req.write('%s did not match<br />' % (item))
else:
req.write('formData was missing either luser, lapp, or lpatient<br />')
else:
req.write("didn't find 'currentPage' or value wasn't 'process_me'<br />")def read_cptfile(filename):
'''This function will import cpt codes into cptBase var.'''
if not os.path.isfile(filename):
raise IOError, "No cpt data found. Please ensure that the path for file (%s) is correct" % (filename)
else:
try:
try: # Open the data file and import it
inFile = open(filename, "r")
for line in inFile:
if line == "": break
if not re.match(line, '^#') and not re.match(line, '^$'):
line = line.strip()
cptCode[line.split(':')[0]],cptDescription[line.split(':')[0]],physicianRVU[line.split(':')[0]],nonFacilityRVU[line.split(':')[0]],malpracticeRVU[line.split(':')[0]],nonFacilityRVU[line.split(':')[0]],cptFee[line.split(':')[0]] = line.split(':')[:]
except IOError: # If file can't be read, we have a problem
print "File '%s' could not be read. Check file permissions." % (filename)
sys.exit()
finally:
inFile.close() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
It may be a permissions problem. By default, Apache executes using a low-privilege user (like 'nobody'), so Apache (and by extension your Python program), may not be able to get access to your files or directories. What permissions have you set up on them?
Other than that, perhaps it's a problem with mod_python. Try experimenting with different file operations and see what happens, and what exceptions they raise. |
|
|
|
|
|
#3 |
|
Programmer
|
For permissions, /var/www and everything inside is owned by nobody / nogroup. Directories are set up as 775 and all files are 664. I'll try some other operations and report what happens.
|
|
|
|
|
|
#4 |
|
Programmer
|
Making progress: In apache 2, the owner of the files has to be www-data (nobody is for apache 1 - my fault for not giving versions of everything). So I can now perform write operations on the dirs. Still can't seem to read the files, but I'm betting it's a configuration error that I've made along the way. I'll post the solution when I find it. Thanks for pointing me in the right direction!
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
Does the apache error log have anything useful to say?
|
|
|
|
|
|
#6 |
|
Programmer
|
Well, I found a solution, though I'm not sure I understand it yet.
For some reason, apache doesn't like it when those files are inside my webdir (/var/www). When I moved them outside to their own location (/data at the moment), it works just fine. Now to figure out how to use mod_python's publisher handler and I should have a usable program. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnlineTextEditor.Com! | Sane | Show Off Your Open Source Projects | 43 | Jun 16th, 2006 8:55 AM |
| Command Prompt | SkyPioneer | Coder's Corner Lounge | 5 | May 3rd, 2006 10:07 PM |
| Help using this function | Eric the Red | Visual Basic | 10 | Feb 27th, 2006 10:26 AM |
| After execution - Error cannot locate /Skin File? | wchar | Visual Basic | 1 | Mar 5th, 2005 9:04 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |