权限错误:venv 中的 sqlite.py 文件

huangapple go评论100阅读模式
英文:

Permission error on sqlite.py file in venv

问题

我需要从Apache2上的Debian启动一个类似的脚本。

$pid = shell_exec(sprintf('nohup /bin/bash /home/debian/Desktop/Holibot/holi.sh > /dev/null 2>&1 & echo $!'));

holi.sh只是激活虚拟环境并运行Python脚本。

然而,我通过pip安装的外部库(kerykeion)在它使用的sqlite.py文件上引发了权限错误13权限被拒绝(用于获取geonames)。但我已经在我的Python项目的文件夹/文件中递归地设置了chmod 777 rwxrwxrwx和chown www-data!

完整的回溯:

2023-06-14 13:40:16,532 - KrInstance - ERROR - 在获取http://api.geonames.org/searchJSON时出错:尝试写入只读数据库

该错误来自

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: 尝试写入只读数据库

当我直接以www-data用户运行脚本时,它可以正常工作,没有权限错误。

theo@x:/home/debian/Desktop/Holibot$ sudo -u www-data bash -c "/home/debian/Desktop/Holibot/holi.sh"

我快疯了!是Apache引起了这个问题吗?为什么我自己运行时它可以正常工作...

英文:

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...

答案1

得分: 0

问题是一个Python库在/var/www/html/而不是/home/debian/Desktop/Holibot/创建了一个文件夹,所以PWD变量不同!

我成功地使用以下方法进行了故障排除:

import traceback
print(traceback.format_exc())

而且www-datahtml/文件夹中没有“wx”的权限,这可能是一个不好的做法?...

英文:

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 ? ...

huangapple
  • 本文由 发表于 2023年6月14日 23:44:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475345.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定