使用 moviepy 给出错误 [Errno 13] 权限被拒绝
using moviepy give error [Errno 13] Permission denied
视频文件上传
def upload_video( video ):
video_name = "%d&&%s%s" % (int(round(time.time() * 1000)), "uservideo", os.path.splitext( video.name )[1])
image_path = '%s/%s' % (DATA_ROOT, video_name)
full_path = '%s%s' % (BASE_DIR, image_path)
try:
with open(full_path,'wb') as fp:
for chunk in video.chunks():
fp.write(chunk)
os.chmod( full_path, 0666 )
except Exception as err:
return image_path
我需要视频文件的缩略图
def ajax_videoUpload( request ):
video = request.FILES[request.FILES.keys()[0]]
videoPath = upload_video( video )
fullPath = "%s%s" % ( BASE_DIR, videoPath )
fileExt = os.path.splitext( videoPath )[1] # file extension
clip = VideoFileClip( fullPath )
fullPath = string.replace( fullPath, fileExt, ".png" )
clip.save_frame( fullPath, t = 10.00 )
thumbnailPath = string.replace( videoPath, fileExt, ".png" )
return HttpResponse( thumbnailPath )
videoFileClip( fullPath ) <-- 给定错误
Traceback (most recent call last):
File "/opt/djangostack-1.8.3-0/apps/django/lib/python2.7/site-packages/Django-1.8.3-py2.7.egg/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/djangostack-1.8.3-0/apps/django/lib/python2.7/site-packages/Django-1.8.3-py2.7.egg/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/djangostack-1.8.3-0/apps/django/django_projects/tellpin/writingform/views.py", line 392, in ajax_videoUpload
clip = VideoFileClip( fullPath )
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/VideoFileClip.py", line 55, in __init__
reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 32, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 237, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
此代码在我的本地运行良好
我本地 OS win7, python 2.7
但无法在服务器中工作
我尝试了文件权限和目录权限
对不起,我是韩国人,所以我的英语不好.....
服务器os分OS6,python2.7.9,django 1.7
如果运行 python 脚本的用户没有正确的文件系统权限来执行您正在尝试的操作,则您无法更改脚本中的用户权限。
您的方法也有缺陷,因为您试图在写入文件后授予自己写入权限。它必须以相反的顺序发生才能解决权限被拒绝的错误。
听起来是这样,但从你的问题中有点难以辨别。
我正在从单元格 phone 中回答,请原谅格式。
从命令行使用 chmod 向用户授予权限 运行 您的脚本。
在没有更多上下文的情况下,我猜这个用户是您的网络服务器用来删除 root 权限的用户。
你的脚本在本地工作的原因是你是 运行 django 的 runsever 用于开发并且它以你的用户身份运行。典型的生产配置使用像 nginx 或 apache 这样的网络服务器,它会更改为安全用户。
视频文件上传
def upload_video( video ):
video_name = "%d&&%s%s" % (int(round(time.time() * 1000)), "uservideo", os.path.splitext( video.name )[1])
image_path = '%s/%s' % (DATA_ROOT, video_name)
full_path = '%s%s' % (BASE_DIR, image_path)
try:
with open(full_path,'wb') as fp:
for chunk in video.chunks():
fp.write(chunk)
os.chmod( full_path, 0666 )
except Exception as err:
return image_path
我需要视频文件的缩略图
def ajax_videoUpload( request ):
video = request.FILES[request.FILES.keys()[0]]
videoPath = upload_video( video )
fullPath = "%s%s" % ( BASE_DIR, videoPath )
fileExt = os.path.splitext( videoPath )[1] # file extension
clip = VideoFileClip( fullPath )
fullPath = string.replace( fullPath, fileExt, ".png" )
clip.save_frame( fullPath, t = 10.00 )
thumbnailPath = string.replace( videoPath, fileExt, ".png" )
return HttpResponse( thumbnailPath )
videoFileClip( fullPath ) <-- 给定错误
Traceback (most recent call last):
File "/opt/djangostack-1.8.3-0/apps/django/lib/python2.7/site-packages/Django-1.8.3-py2.7.egg/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/djangostack-1.8.3-0/apps/django/lib/python2.7/site-packages/Django-1.8.3-py2.7.egg/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/djangostack-1.8.3-0/apps/django/django_projects/tellpin/writingform/views.py", line 392, in ajax_videoUpload
clip = VideoFileClip( fullPath )
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/VideoFileClip.py", line 55, in __init__
reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 32, in __init__
infos = ffmpeg_parse_infos(filename, print_infos, check_duration)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/site-packages/moviepy/video/io/ffmpeg_reader.py", line 237, in ffmpeg_parse_infos
proc = sp.Popen(cmd, **popen_params)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/djangostack-1.8.3-0/python/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
此代码在我的本地运行良好 我本地 OS win7, python 2.7 但无法在服务器中工作
我尝试了文件权限和目录权限
对不起,我是韩国人,所以我的英语不好.....
服务器os分OS6,python2.7.9,django 1.7
如果运行 python 脚本的用户没有正确的文件系统权限来执行您正在尝试的操作,则您无法更改脚本中的用户权限。
您的方法也有缺陷,因为您试图在写入文件后授予自己写入权限。它必须以相反的顺序发生才能解决权限被拒绝的错误。
听起来是这样,但从你的问题中有点难以辨别。
我正在从单元格 phone 中回答,请原谅格式。
从命令行使用 chmod 向用户授予权限 运行 您的脚本。
在没有更多上下文的情况下,我猜这个用户是您的网络服务器用来删除 root 权限的用户。
你的脚本在本地工作的原因是你是 运行 django 的 runsever 用于开发并且它以你的用户身份运行。典型的生产配置使用像 nginx 或 apache 这样的网络服务器,它会更改为安全用户。