IOError: [Errno 13] Permission denied

狂风中的少年 提交于 2019-12-23 02:56:05

问题


I'm getting a permission error when trying to save a screenshot from Sikuli under Windows. The code that's doing the capturing is:

def CaptureScreenshot(self):
    resultsDirectory = os.path.join('C','08 May 2013 11 34','myname.png')
    screenshot = capture(self.screen)
    print(screenshot)
    shutil.move(screenshot,self.resultsDirectory)

When I print the screenshot path returned by capture, I get

D:\DOCUME~1\BUNNINGS\LOCALS~1\Temp\sikuli-scr-366782306192033926.png

When I run the code, I get this error:

Traceback (most recent call last):
  File "__pyclasspath__/Tests/Tests.py", line 12, in tearDown
  File "__pyclasspath__/Scripts/Screen.py", line 39, in CaptureScreenshot
  File "C:\jython2.5.3\Lib\shutil.py", line 205, in move
    copy2(src,dst)
  File "C:\jython2.5.3\Lib\shutil.py", line 96, in copy2
    copyfile(src, dst)
  File "C:\jython2.5.3\Lib\shutil.py", line 52, in copyfile
    fdst = open(dst, 'wb')
IOError: [Errno 13] Permission denied: 'C\\08 May 2013 11 34\\myname.png'

The destination folder exists and myname.png is the new name I am trying to give to the image.

I noticed that the destination folder's properties are set to "read only". Is this causing the issue? I couldn't change the readonly attribute; when I try, it just goes back to readonly.


回答1:


There seems to be a colon missing after the C in your path. You are now trying to write in a subdirectory 'C' of the current directory.

Try to change the second line into:

resultsDirectory = os.path.join('C:','08 May 2013 11 34','myname.png')
                                  ^


来源:https://stackoverflow.com/questions/16432393/ioerror-errno-13-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!