英文:
Errno 13 permission denied on gcloud VM Instance
问题
我在Gcloud Instance上使用了这段代码:
from PIL import Image
from PIL import ImageOps
filename = 'marmoreio_red_2.jpg'
img = Image.open(filename)
val = 10 #--- 要裁剪的像素
#--- 在所有边上都有10像素边框的新图像
#--- 注意fill参数使用白色的颜色表示为(255, 255, 255)
new_img = ImageOps.expand(img, border=val, fill=(0, 0, 255))
#--- 对上面的图像进行裁剪不会导致任何黑色部分
cropped = new_img.crop((val, val, 150, 150))
cropped.save('img_teste.jpg', 'JPEG')
这段代码是正确的,但是在Gcloud Instance上没有正常工作。我收到了以下错误信息:
fp = builtins.open(filename, "w+b")
PermissionError: [Errno 13] Permission denied: 'img_teste.jpg'
我尝试了很多方法,比如这个:
https://www.skynats.com/blog/how-to-fix-the-ftp-permission-denied-error-in-google-cloud-platform/
但是我没有找到这个文件:
/etc/apache2/sites-available/wordpress.conf
这是关于我的Instance的一些附加信息:
[![enter image description here][1]][1]
[![enter image description here][2]][2]
我对此感到非常困扰,有什么建议吗?
[1]: https://i.stack.imgur.com/ku5dw.png
[2]: https://i.stack.imgur.com/BxL68.png
英文:
I used this code on Gcloud Instance:
from PIL import Image
from PIL import ImageOps
filename = 'marmoreio_red_2.jpg'
img = Image.open(filename)
val = 10 #--- pixels to be cropped
#--- a new image with a border of 10 pixels on all sides
#--- also notice fill takes in the color of white as (255, 255, 255)
new_img = ImageOps.expand(img, border = val, fill = (0, 0, 255))
#--- cropping the image above will not result in any black portion
cropped = new_img.crop((val, val, 150, 150))
cropped.save('img_teste.jpg','JPEG')
The code is ok, but did'nt work just on Gcloud Instance. I received this message:
fp = builtins.open(filename, "w+b")
PermissionError: [Errno 13] Permission denied: 'img_teste.jpg'
I tried several approachs like this:
https://www.skynats.com/blog/how-to-fix-the-ftp-permission-denied-error-in-google-cloud-platform/
But I don´t have this file:
/etc/apache2/sites-available/wordpress.conf
Here some additional information about my Instance:
I'm crazy with this, some suggestion, please?
答案1
得分: 2
更改目录所有权:如果运行Python代码的用户没有对目录的写权限,您可以尝试使用chown命令将目录的所有权更改为该用户:
sudo chown -R user:user directory_path。
英文:
I got it.
Change the ownership of the directory: If the user running the Python code does not have write permissions to the directory, you can try changing the ownership of the directory to the user by using the chown command:
sudo chown -R user:user directory_path.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论