I’m attempting to write a CGI script to control my explorer hat from a web page. The hat works fine with runtime scripts.
#!/usr/bin/env python import cgi import cgitb cgitb.enable() print ("Content-type: text/html\n\n") print ("<h1>Hello World</h1>") import explorerhat import RPi.GPIO as GPIO # import a library
The script works fine as a runtime script and works in cgi if I remove the line “import explorerhat” however, when the import is present I get:
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/usr/lib/cgi-bin/motor.py in ()
=> 11 import explorerhat
12 import RPi.GPIO as GPIO # import a library
/usr/lib/python2.7/dist-packages/explorerhat/init.py in ()
26 exit(“This library requires the cap1xxx module\nInstall with: sudo pip install cap1xxx”)
=> 28 from .ads1015 import read_se_adc, adc_available
29 from .pins import ObjectCollection, AsyncWorker, StoppableThread
read_se_adc undefined, adc_available undefined
/usr/lib/python2.7/dist-packages/explorerhat/ads1015.py in ()
21 address = 0x48
=> 22 i2c = SMBus(i2c_bus_id())
24 REG_CONV = 0x00
i2c undefined, SMBus = None, i2c_bus_id = None
<type ‘exceptions.IOError’>: [Errno 13] Permission denied
args = (13, ‘Permission denied’)
errno = 13
filename = None
message = ''
strerror = ‘Permission denied’
I have run:
sudo chown -R www-data /usr/lib/python2.7/dist-packages
sudo chmod -R 777 /usr/lib/python2.7/dist-packages
Any assistance would be greatly appreciated.