Python OSError - Errno 13 权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23870808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OSError - Errno 13 Permission denied
提问by doniyor
I am trying to upload image through admin page, but it keeps saying:
我正在尝试通过管理页面上传图片,但它一直说:
[Errno 13] Permission denied: '/path/to/my/site/media/userfolder/2014/05/26'
the folders userfolder/2014/05/26are created dynamically while uploading.
文件夹 userfolder/2014/05/26是在上传时动态创建的。
In Traceback, i found that the error is occuring during this command:
在 Traceback 中,我发现在此命令期间发生错误:
In /usr/lib64/python2.6/os.py Line 157. while calling
在 /usr/lib64/python2.6/os.py 第 157 行。同时调用
mkdir(name, mode)
meaning, it cannot create any folder as it doesnot have the permission to do this
意思是,它不能创建任何文件夹,因为它没有执行此操作的权限
I have OpenSuse as OS in Server. In httpd.conf, i have this:
我在服务器中使用 OpenSuse 作为操作系统。在 httpd.conf 中,我有这个:
<Directory /path/to/my/site/media>
Order allow,deny
Allow from all
</Directory>
Do I have to chmod or chown something?
我必须 chmod 或 chown 什么吗?
采纳答案by falsetru
You need to change the directory permission so that web server process can change the directory.
您需要更改目录权限,以便 Web 服务器进程可以更改目录。
To change ownership of the directory, use
chown:chown -R user-id:group-id /path/to/the/directoryTo see which user own the web server process (change
httpdaccordingly):ps aux | grep httpd | grep -v grepOR
ps -efl | grep httpd | grep -v grep
要更改目录的所有权,请使用
chown:chown -R user-id:group-id /path/to/the/directory要查看哪个用户拥有 Web 服务器进程(相应地更改
httpd):ps aux | grep httpd | grep -v grep或者
ps -efl | grep httpd | grep -v grep
回答by mjp
This may also happen if you have a slash before the folder name:
如果文件夹名称前有斜杠,也可能会发生这种情况:
path = '/folder1/folder2'
OSError: [Errno 13] Permission denied: '/folder1'
comes up with an error but this one works fine:
出现了一个错误,但这个工作正常:
path = 'folder1/folder2'
回答by Karan Chopra
Probably you are facing problem when a download request is made by the maybe_download function call in base.py file.
当 base.py 文件中的maybe_download 函数调用发出下载请求时,您可能会遇到问题。
There is a conflict in the permissions of the temporary files and I myself couldn't work out a way to change the permissions, but was able to work around the problem.
临时文件的权限存在冲突,我自己无法找到更改权限的方法,但能够解决该问题。
Do the following...
请执行下列操作...
- Download the four .gz files of the MNIST data set from the link ( http://yann.lecun.com/exdb/mnist/)
- Then make a folder names MNIST_data (or your choice in your working directory/ site packages folder in the tensorflow\examples folder).
- Directly copy paste the files into the folder.
- Copy the address of the folder (it probably will be ( C:\Python\Python35\Lib\site-packages\tensorflow\examples\tutorials\mnist\MNIST_data ))
- Change the "\" to "/" as "\" is used for escape characters, to access the folder locations.
- Lastly, if you are following the tutorials, your call function would be ( mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ); change the "MNIST_data/"parameter to your folder location. As in my case would be ( mnist = input_data.read_data_sets("C:/Python/Python35/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data", one_hot=True) )
- 从链接 ( http://yann.lecun.com/exdb/mnist/)下载 MNIST 数据集的四个 .gz 文件
- 然后创建一个名为 MNIST_data 的文件夹(或者您在 tensorflow\examples 文件夹中的工作目录/站点包文件夹中选择)。
- 直接将文件复制粘贴到文件夹中。
- 复制文件夹的地址(它可能是( C:\Python\Python35\Lib\site-packages\tensorflow\examples\tutorials\mnist\MNIST_data ))
- 将“\”更改为“/”,因为“\”用于转义字符,以访问文件夹位置。
- 最后,如果您正在学习教程,您的调用函数将是( mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) ); 将“MNIST_data/”参数更改为您的文件夹位置。就像我的情况一样( mnist = input_data.read_data_sets("C:/Python/Python35/Lib/site-packages/tensorflow/examples/tutorials/mnist/MNIST_data", one_hot=True) )
Then it's all done. Hope it works for you.
然后一切都完成了。希望对你有效。
回答by Jacob Weiss
Another option is to ensure the file is not open anywhere else on your machine.
另一种选择是确保文件不会在您机器上的任何其他地方打开。
回答by Rubens_Zimbres
Simply try:
只需尝试:
sudo cp /source /destination
回答by Balaji
Just close the file in case it is opened in the background. The error disappears by itself
只需关闭文件,以防它在后台打开。错误自行消失

