Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-12-2005, 03:00 PM
|
#1
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Rep:
|
Python CGI script can't write files, permission denied
Ok, I have my python CGI script, and it isn't able to write to my config file (which is named config.cfg). First it wasn't able to open the file at all. So I did a touch config.cfg, and a chmod 777 config.cfg, but still it can't open the file for writing ("Permission denied"). So, since it was in my ScriptAlias directory, I thought maybe that was the problem, so I made a new directory, and put it in that, so now it is in test/config.cfg. It still wont work! I've tried changing users, modes, everything on the file and all the directories leading to the file, but still I get the same error. Anyone got any ideas?
|
|
|
03-13-2005, 10:47 AM
|
#2
|
Member
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217
Rep:
|
Can you post some code?
|
|
|
03-14-2005, 12:17 AM
|
#3
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Original Poster
Rep:
|
Code:
#!/usr/bin/python
import cgi, cgitb; cgitb.enable()
print "Content-Type: text/html\n\n" # HTML is following
#print # blank line, end of headers
class IncomeChunk:
Type = 0
Amount = 0.00
Description = ""
IncomeSplits = []
def LoadCFG():
global IncomeSplits
try:
Handle = open("accounting/config.cfg", "rb")
except:
print "Error: Unable to open config file for reading"
return
try:
Line = Handle.readline()
Splits = Line.split(",")
del IncomeSplits[:]
for I in Splits:
Data = I.split(":")
Chunk = IncomeChunk()
Chunk.Type = int(Data[0])
Chunk.Amount = float(Data[1])
Chunk.Description = str(Data[2])
IncomeSplits.append(Chunk)
except:
print "Error: Unable to load configuration"
return
Handle.close()
def SaveCFG():
global IncomeSplits
Handle = open("accounting/config.cfg", "wb")
#except:
# print "Error: Unable to open config file for writing"
# return
for I in IncomeSplits:
if I != IncomeSplits[0]: Handle.write(",")
Handle.write("%d:%f:%s"%(I.Type, I.Amount, I.Description))
Handle.write("\n")
Handle.close()
Form = cgi.FieldStorage()
Action = Form.getvalue("_cmd")
print "<html><body bgcolor=\"#205fd4\" text=\"#ffffff\">"
LoadCFG()
if Action == "add_split":
Amount = Form.getvalue("amount")
Description = Form.getvalue("description")
if '%' in str(Amount):
Chunk = IncomeChunk()
Chunk.Type = int(0)
Chunk.Amount = float(Amount.strip("%%"))
Chunk.Description = str(Description)
else:
Chunk = IncomeChunk()
Chunk.Type = int(1)
Chunk.Amount = float(Amount)
Chunk.Description = str(Description)
IncomeSplits.append(Chunk)
SaveCFG()
print "<table border=\"1\" with=\"100%%\">"
print "<tr>"
print "<td>"
print "Amount - Amount of money for this split (put a %% for a percentage)"
print "</td>"
print "<td>"
print "Description - Description of split "
print "</td>"
print "<td>"
print "</td>"
print "</tr>"
Index = 0
while(Index < len(IncomeSplits)):
I = IncomeSplits[Index]
print "<form method=\"post\" action=\"accounting.py\">"
print "<tr>"
print "<td>"
if I.Type == 0:
print "<input type=\"text\" value=\"%s%%\" name=\"amount\">"%str(I.Amount)
elif I.Type == 1:
print "<input type=\"text\" value=\"%s$\" name=\"amount\">"%str(I.Amount)
print "</td>"
print "<td>"
print "<input type=\"text\" value=\"%s\" name=\"description\">"%I.Description
print "</td>"
print "<td>"
print "<input type=\"submit\" value=\"Edit\">"
print "</td>"
print "</tr>"
print "<input type=\"hidden\" name=\"_cmd\" value=\"edit_split\">"
print "<input type=\"hidden\" name=\"_index\" value=\"%d\">"%Index
print "</form>"
Index = Index + 1
print "<form method=\"post\" action=\"accounting.py\">"
print "<tr>"
print "<td>"
print "<input type=\"text\" value=\"\" name=\"amount\" size=\"50\">"
print "</td>"
print "<td>"
print "<input type=\"text\" value=\"\" name=\"description\" size=\"100\">"
print "</td>"
print "<td>"
print "<input type=\"submit\" value=\" Add \">"
print "</td>"
print "</tr>"
print "<input type=\"hidden\" name=\"_cmd\" value=\"add_split\">"
print "</form>"
print "</table>"
print "</body></html>"
That is my complete script, however the problem is in SaveCFG. It is going to be a script to help me split my income into percentages or raw amounts.
|
|
|
03-14-2005, 05:55 AM
|
#4
|
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503
Rep:
|
Have you tried changing up the modes on your Handles?
Handle = open("accounting/config.cfg", "w")
Also, and this may not make a difference, try putting the full path to config.cfg. I've had some issues with the open method as well and it seems to be very picky at some times.
|
|
|
03-17-2005, 12:19 PM
|
#5
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Original Poster
Rep:
|
Still doesn't work. I've tried everything, including all the things you guys suggested. So I just put my script on another server, and it works fine!  Sheesh! Anyhow, thanks for the replies. If anybody does truely know the problem, than let me know! Thanks!
|
|
|
All times are GMT -5. The time now is 10:29 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|