简体   繁体   中英

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.

The script gives a permission error when run via apache as user www-data:

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:

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

The script still runs smoothly from the CLI as regular user:

$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:

$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())

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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