1
我有一些問題。從php執行python文件錯誤
這個php(uploads.php)腳本執行gif.py python文件。
<?php
$file_path = "uploads/";
$auth_token = $_POST['auth_token'];
mysql_connect('localhost',"login",'pass');
mysql_set_charset("UTF-8");
mysql_select_db("DB_name");
$sql = "SELECT user_id FROM users WHERE auth_token='$auth_token'";
$result = mysql_query($sql);
if(mysql_fetch_array($result)['user_id']==0)
{
echo "fail auth_token ".$auth_token;
exit;
}
$file_md5 = md5(time()+$auth_token+rand(0,1000));
$file_path = $file_path . basename($_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], "uploads/".$file_md5.".mp4")) {
$aaa = exec("/usr/bin/python gif.py b9022c5c317cf2317ad3f537dcc1cfbe");
echo $file_md5." ".$aaa;
} else{
echo "fail ".$_FILES['uploaded_file']['size']." ".$_FILES['uploaded_file']['tmp_name']." ".$file_path ;
}
?>
gif.py文件
#!/usr/bin/env python
from moviepy.editor import *
import sys
file_md5 = sys.argv[1]
anna_olaf = (VideoFileClip("uploads/" + file_md5+".mp4")
.subclip(0,1)
.resize(1))
anna_olaf.write_gif('gifs/test.gif', fps=15)
我在上傳文件夾b9022c5c317cf2317ad3f537dcc1cfbe.mp4
文件。在哪裏我從Linux控制檯調用gif.py或uploads.php文件一切正常(php uploads.php或pyhon gif.py),但我從瀏覽器python文件調用uploads.php不工作,在Apache日誌中我找到
/usr/lib/python2.7/dist-packages/IPython/utils/path.py:296: UserWarning: IPython parent '/var/www' is not a writable location, using a temp directory.
" using a temp directory."%parent)
Traceback (most recent call last):
File "gif.py", line 2, in <module>
from moviepy.editor import *
File "/usr/local/lib/python2.7/dist-packages/moviepy-0.2.1.8.12-py2.7.egg/moviepy/editor.py", line 45, in <module>
from .video.io.sliders import sliders
File "/usr/local/lib/python2.7/dist-packages/moviepy-0.2.1.8.12-py2.7.egg/moviepy/video/io/sliders.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 774, in <module>
rcParams = rc_params()
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 692, in rc_params
fname = matplotlib_fname()
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 604, in matplotlib_fname
fname = os.path.join(get_configdir(), 'matplotlibrc')
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 253, in wrapper
ret = func(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 478, in _get_configdir
raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)
RuntimeError: Failed to create /var/www/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data
請幫幫忙,在日誌寫入錯誤在2號線(從moviepy.editor進口*),但爲什麼我沒有錯誤的調用(蟒蛇gif.py)?
錯誤未顯示在錯誤報告的最後一行: 'RuntimeError:無法創建/var/www/.matplotlib;考慮將MPLCONFIGDIR設置爲matplotlib配置數據的可寫目錄# 我想說這可能是'/ var/www /'文件夾的權限問題,不允許腳本根據需要創建文件。 – Kypros 2014-10-10 16:42:40
ooooo yeeeeeeeeeeeees !!! thaaaaaaaaaaaaaaaaank你求助。 :) – 2014-10-10 16:54:21
我會發表評論作爲答案,以防其他人遇到類似問題。 – Kypros 2014-10-10 16:55:28