Python Forum

Full Version: Using a imported module in python via pache results in permission denied error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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())
solved!
permissions on ...../lightning-rpc and all higher folders were not set for www-data access. now it works

this thead can be closed