Errno 13权限被拒绝在gcloud虚拟机实例上。

huangapple go评论65阅读模式
英文:

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:
Errno 13权限被拒绝在gcloud虚拟机实例上。
Errno 13权限被拒绝在gcloud虚拟机实例上。

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.

huangapple
  • 本文由 发表于 2023年3月7日 07:48:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定