简体   繁体   English

在python中使用导入的模块会导致权限被拒绝错误

[英]Using a imported module in python result in permission denied error

I'm trying to use a imported module (pylightning) in a python script that runs using apache under user www-data. 我正在尝试在用户www-data下使用apache运行的python脚本中使用导入的模块(pylightning)。

The script gives a permission error when run via apache as user www-data: 当以用户www-data的身份通过apache运行时,脚本给出了权限错误:

File "/usr/local/lib/python3.4/dist-packages/lightning/lightning.py", line 69, in call
sock.connect(self.socket_path)
PermissionError: [Errno 13] Permission denied

To fix this I have intensively searched and found i needed to reinstall the module as www-data user: 为了解决这个问题,我进行了深入搜索,发现我需要以www-data用户身份重新安装该模块:

sudo pip3 uninstall pylightning
sudo -H -u www-data pip3 install pylightning

The script still runs smoothly from the CLI as regular user: 该脚本仍可以作为常规用户从CLI顺利运行:

$python3 index.py
Content-Type: text/html


<html><body>
etc...

But from apache (through a browser or from the command line as user www-data) still gives the same error: 但是从apache(作为用户www-data通过浏览器或从命令行)仍然给出相同的错误:

$sudo -u www-data python3 /var/www/html/index.py
Content-Type: text/html


<html><body>
Traceback (most recent call last):
File "/var/www/html/index.py", line 29, in <module>
print(rpc_interface.listpeers())
File "/usr/local/lib/python3.4/dist-packages/lightning/lightning.py", line 345, in listpeers
return self.call("listpeers", payload)
File "/usr/local/lib/python3.4/dist-packages/lightning/lightning.py", line 69, in call
sock.connect(self.socket_path)
PermissionError: [Errno 13] Permission denied

Anyone has any idea here? 有人在这里有想法吗?

Script source: 脚本来源:

#!/usr/bin/env python3

import hashlib
from lightning.lightning import LightningRpc

rpc_interface = LightningRpc("/home/pi/.lightning/lightning-rpc")
print ("Content-Type: text/html\n\n");
print ("</body></html>asd");
print(rpc_interface.listpeers())

the error triggers on this line: print(rpc_interface.listpeers()) 错误将在此行触发:print(rpc_interface.listpeers())

验证www数据用户是否有权访问/home/pi/.lightning/lightning-rpc (包括父目录)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM