[英]python cgi PermissionError: [Errno 13] Permission denied:
[英]Permission denied,Python , CGI ,Apache
嗨,我正嘗試在我的/usr/lib/cgi-bin/mcp3008.py中運行此python代碼。我正在使用樹莓派PI和Apache服務器。 我對此很陌生,謝謝
#!/usr/bin/env python
#--------------------------------------
# This script reads data from a
# MCP3008 ADC device using the SPI bus.
#
# Author : Matt Hawkins
# Date : 13/10/2013
#
# http://www.raspberrypi-spy.co.uk/
#
#--------------------------------------
import spidev
import time
import os
print "Content-type: text/html\n\n"
print "<bold>Light:</bold>"
# Open SPI bus
spi = spidev.SpiDev()
spi.open(0,0)
# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data
# Function to convert data to voltage level,
# rounded to specified number of decimal places.
def ConvertVolts(data,places):
volts = (data * 3.3) / float(1023)
volts = round(volts,places)
return volts
# Function to calculate temperature from
# TMP36 data, rounded to specified
# number of decimal places.
# TMP36 data, rounded to specified
# number of decimal places.
def ConvertTemp(data,places):
# ADC Value
# (approx) Temp Volts
# 0 -50 0.00
# 78 -25 0.25
# 155 0 0.50
# 233 25 0.75
# 310 50 1.00
# 388 75 1.25
# 465 100 1.50
# 543 125 1.75
# 620 150 2.00
# 698 175 2.25
# 775 200 2.50
# 853 225 2.75
# 930 250 3.00
# 1008 275 3.25
# 1023 280 3.30
temp = ((data * 330)/float(1023))-50
temp = round(temp,places)
return temp
# Define sensor channels
light_channel = 0
temp_channel = 1
# Define delay between readings
delay = 5
while True:
# Read the light sensor data
light_level = ReadChannel(light_channel)
light_volts = ConvertVolts(light_level,2)
light_volts = ConvertVolts(light_level,2)
# Read the temperature sensor data
temp_level = ReadChannel(temp_channel)
temp_volts = ConvertVolts(temp_level,2)
temp = ConvertTemp(temp_level,2)
# Print out results
print "------The 'Ponics Project--------------------------------------"
print("Light : {} ({}V)".format(light_level,light_volts))
print("Temperature in the room is: {} ({}V) {} deg F".format(temp_level,temp_volts,(temp * 9/5)+ 32))
# Wait before repeating loop
time.sleep(delay)
問題是我得到一個錯誤。 這就是我的var / log / apache2 / error.log的樣子
[Wed Apr 29 21:15:37 2015] [error] [client 192.168.2.1] Traceback (most recent call last):
[Wed Apr 29 21:15:37 2015] [error] [client 192.168.2.1] File "/usr/lib/cgi-bin/mcp3008.py", line 21, in <module>
[Wed Apr 29 21:15:37 2015] [error] [client 192.168.2.1]
[Wed Apr 29 21:15:37 2015] [error] [client 192.168.2.1] spi.open(0,0)
[Wed Apr 29 21:15:37 2015] [error] [client 192.168.2.1] IOError: [Errno 13] Permission denied
[Wed Apr 29 21:15:38 2015] [error] [client 192.168.2.1] File does not exist: /var/www/favicon.ico, referer: http://192.168.2$
為了允許您在Apache Web服務器上運行的Web程序與SPI設備通信,您需要為運行Apache Web服務器的用戶帳戶提供SPI設備的權限。 輸入此命令:
須藤usermod -a -G spi www-data
您需要重新引導PI才能使更改生效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.