sqlite3 permission issue

C

chris

I am trying to execute an update to a sqlite3 db via a python cgi
script. I can execute a select via a cgi script, but when I attempt
an update, I get an "unable to open database file" error. But the
error comes on the update statement, not on the connect.

So the script has:

conn = sqlite3.connect('db')
c = conn.cursor()
--we get here ok--
c.execute("insert into contact ...") <-- this statement produces the
error

I can run the exact same python code from the command line and it
works, so it has something to do with the user that runs the cgi
(apache I assume). I chmodded the db file to 666, but it did not
help.

Any ideas?

Thanks,
Chris
 
C

chris

I am trying to execute an update to a sqlite3 db via a python cgi
script. I can execute a select via a cgi script, but when I attempt
an update, I get an "unable to open database file" error. But the
error comes on the update statement, not on the connect.

So the script has:

conn = sqlite3.connect('db')
c = conn.cursor()
--we get here ok--
c.execute("insert into contact ...") <-- this statement produces the
error

I can run the exact same python code from the command line and it
works, so it has something to do with the user that runs the cgi
(apache I assume). I chmodded the db file to 666, but it did not
help.

Any ideas?

Thanks,
Chris

Nevermind, it was the directory permissions causing the issue. Works
now.
 
T

Tim Chase

I am trying to execute an update to a sqlite3 db via a python cgi

If you're running as a CGI, your script (as you guess below) will
usually run with the effective permissions of the web-server.
Frequently, this is some user such as "wwwdata" or "www".
conn = sqlite3.connect('db')

Make sure that this is fully qualified:

dbname = '/path/to/where/www/can/write/db'
conn = sqlite3.connect(dbname)

In addition, if your local user ("cstromberger" for example) owns
that DB file, you'll need to make sure that www can access that file:

bash> chown :wwwdata db

(assuming the webserver runs with GID "wwwdata") and then make
sure you've got 660 permissions on it (rw-rw----). Issuing a
chown as non-root may be disallowed.
I can run the exact same python code from the command line and it
works, so it has something to do with the user that runs the cgi
(apache I assume). I chmodded the db file to 666, but it did not
help.

If the DB file is truly read/write as you describe, I'm guessing
that the path has not been properly resolved. It might be lazily
opening the file, failing on first access rather than on the
connect() call.

You might also check to see if your Apache is running in a chroot
jail which may prevent it from seeing files in particular paths
outside that jail.

Just a few ideas to test. If you know you can open the file and
read from it (the path is fully-qualified and you have permission
to open the file), then make sure your permitted to. It may help
to make some stat() calls on the file to ensure that it's really
where you think it is, and has the permissions you think it has.

Hope they help,

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top