sqlite3 permission issue

Tim Chase python.list at tim.thechases.com
Tue Mar 4 17:02:02 EST 2008


> 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







More information about the Python-list mailing list