View Single Post
Old Jan 15th, 2007, 12:10 PM   #1
somehollis
Programmer
 
somehollis's Avatar
 
Join Date: May 2006
Location: Memphis, TN
Posts: 31
Rep Power: 0 somehollis is on a distinguished road
Send a message via AIM to somehollis
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 />")
Main program's import function (the first one called by audiclock.read_all() ) The filename being passed to this function is any of what I have tried above (e.g. /var/www/data/cptcodes2007)
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()
somehollis is offline   Reply With Quote