Python Forum
Using a imported module in python via pache results in permission denied error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a imported module in python via pache results in permission denied error
#1
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())
Reply
#2
solved!
permissions on ...../lightning-rpc and all higher folders were not set for www-data access. now it works

this thead can be closed
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python project - sport results Qn91 3 1,759 Oct-10-2022, 08:48 AM
Last Post: Larz60+
  Python web crawler and input command not having the correct results see below for mor samlee916 0 1,461 Jul-25-2020, 08:24 PM
Last Post: samlee916
  Acces to page denied julio2000 1 8,005 Feb-08-2020, 02:37 AM
Last Post: Larz60+
  Python Import Sybase Module returning non explicit error thebeefes 2 5,851 Mar-14-2019, 07:32 PM
Last Post: Carlos

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020