Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
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
Old Jan 15th, 2007, 12:22 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Jan 15th, 2007, 12:36 PM   #3
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
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.
somehollis is offline   Reply With Quote
Old Jan 15th, 2007, 2:27 PM   #4
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
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!
somehollis is offline   Reply With Quote
Old Jan 15th, 2007, 8:12 PM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Does the apache error log have anything useful to say?
Arevos is offline   Reply With Quote
Old Jan 17th, 2007, 9:50 PM   #6
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
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.
somehollis is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC