Search code examples
python-3.xlinuxbashapachepermissions

Permission error on sqlite.py file in venv


I need to launch a script like that from Apache2 on debian $pid = shell_exec(sprintf('nohup /bin/bash /home/debian/Desktop/Holibot/holi.sh > /dev/null 2>&1 & echo $!'));

The holi.sh just activate the venv and run the python script.

However an external lib (kerykeion) I've pip installed raises a permission error 13 permission denied on a sqlite.py file base it uses (for geonames fetching). But I have put chmod 777 rwxrwxrwx and chown www-data recursively everywhere in my folders/files of python project !!! The script .py run well with www-data user and crashes during execution with the error...

Full traceback :

2023-06-14 13:40:16,532 - KrInstance - ERROR - Error in fetching http://api.geonames.org/searchJSON: attempt to write a readonly database

Which error comes from

self.responses[cache_key] = cached_response
  File "/home/debian/Desktop/Holibot/venv/lib/python3.9/site-packages/requests_cache/backends/sqlite.py", line 283, in __setitem__
    con.execute(
sqlite3.OperationalError: attempt to write a readonly database

And when I run the script directly with www-data it works without the perm error... theo@x:/home/debian/Desktop/Holibot$ sudo -u www-data bash -c "/home/debian/Desktop/Holibot/holi.sh"

I am going crazy ! Is it Apache which causes this issue? Why does it work when I run it myself...


Solution

  • The problem was that a python lib created a folder in /var/www/html/ instead of /home/debian/Desktop/Holibot/ so the PWD variables was different !

    I did successfully troubleshooted with

    import traceback
    print(traceback.format_exc())
    

    And the www-data had no perm to "wx" in html/ folders which maybe a bad practice ? ...