dongqi8863 2017-01-10 03:00
浏览 196

从PHP打开python脚本时权限被拒绝

I have a PHP script that will create and append data to a text document. The script will then execute a python script that will read over that document, and move create a different document else where on the raspberry pi. I have been looking for the past several hours at different solutions, and they all seem to boil down to permissions. Based on what I have found, I have set the following:

-rwxrwxrwx 1 www-data www-data 314 Jan 9 16:09 AlbumString.py

-rwxrwxrwx 1 www-data www-data 74 Jan 9 21:31 display.txt

The AlbumString.py is the python script, the display.txt is where the PHP file rights to, and the Python script reads from. Further research somone suggested looking at the error logs for apache. When I looked at this I saw that I was getting a permission error:

Traceback (most recent call last):
  File "AlbumString.py", line 13, in <module>
    display = open('/media/pi/external/Photos/' + templist.pop(0),'a')
PermissionError: [Errno 13] Permission denied: '/media/pi/external/Photos/Erik.txt'

My python code will create or append a file if it already exists. In the case of running this iteration, the file Erik.txt did not exist, so it would have had to create it. The code for AlbumString.py:

#!/usr/bin/python

import sys
import json
import base64

album = open('/var/www/html/uploads/display.txt')
templist = []
a= 0
for x in album:
    templist.append(x.rstrip('
'))
album.close()
display = open('/media/pi/external/Photos/' + templist.pop(0),'a')
for x in templist:
    display.write(x+'
')
display.close()

The PHP code that I am using to call the python script:

fclose($fh);
$testing = shell_exec("python3 AlbumString.py");
if(!$testing){
    echo "You are a failure!<br>";
} else {
    echo "You are a genius<br>";
}
      echo "end of document";
}

I have also added www-data to my sudoers file, which is not suggested but that I would give it a chance, and nothing has worked. The PHP correctly writes to the file, and if I call the python script from a console, that properly executes as well.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
    • ¥15 unity连接Sqlserver
    • ¥15 图中这种约束条件lingo该怎么表示出来
    • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
    • ¥15 流式socket文件传输答疑
    • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
    • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
    • ¥15 win10,这种情况怎么办
    • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
    • ¥100 在连接内网VPN时,如何同时保持互联网连接