Posts: 4
Threads: 1
Joined: Apr 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
I'm trying to write a script to automate some things for a project I'm working on, and one of the steps is saving a file as a png. I'm using file_png_save2. When running the script, it errors out with a "Permission Denied" message. However, I can save files to the same folder with no issue if I go through File->Export.
I'm running Gimp 2.10 on Windows 11. Here is the code for the script so far:
#!/usr/bin/python
from gimpfu import *
baseURL = "C:\\Users\\MyID\\OneDrive\\Pictures\\ScriptTest\\"
def char_img_164(image, drawable, imgid):
pdb.gimp_edit_copy(image.layers[0])
newImg = pdb.gimp_edit_paste_as_new_image()
pdb.gimp_image_scale(newImg, 164, 164)
dispImg = pdb.gimp_display_new(newImg)
layer = pdb.gimp_image_merge_visible_layers(newImg, CLIP_TO_IMAGE)
pdb.file_png_save2(newImg, layer, baseURL + "test1",imgid+".png",0,9,0,0,0,0,0,0,0)
register(
"char_img_164",
"Image test",
"Test script",
"MyID",
"MyID",
"2023",
"<Image>/Image/ScriptTest/IMG164",
"*",
[
(PF_STRING, "imgid", "Enter ID", "hello")
],
[],
char_img_164)
main()
Posts: 6,339
Threads: 272
Joined: Oct 2016
Reputation:
562
Operating system(s):
Gimp version: 2.10
04-29-2023, 10:04 PM
(This post was last modified: 04-29-2023, 10:06 PM by Ofnuts.)
Nothing obvious, so:
- Check the system security log, perhaps the python interpreter is blacklisted and it (or its children) are not allowed to write to disk.
- If you catch the exception and print the exception message, you could have more info (see here for some hints)
- The OneDrive directory could have a special status, and this isn't difficult to check by writing elsewhere.
- I assume that MyId is replaced by the adequate username
- Your first name parameter has no extension, so I wonder what the real name is and what it does
Also:
- You can avoid the double \\ by using r-strings: r"C:\Users\MyID\OneDrive\Pictures\ScriptTest\", but forward slashes also work on Windows: "C:/Users/MyID/OneDrive/Pictures/ScriptTest/"
- The os.path module has a join method to create correct paths from directories and file names.
Posts: 4
Threads: 1
Joined: Apr 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
(04-29-2023, 10:04 PM)Ofnuts Wrote: Nothing obvious, so:
- Check the system security log, perhaps the python interpreter is blacklisted and it (or its children) are not allowed to write to disk.
- If you catch the exception and print the exception message, you could have more info (see here for some hints)
- The OneDrive directory could have a special status, and this isn't difficult to check by writing elsewhere.
- I assume that MyId is replaced by the adequate username
- Your first name parameter has no extension, so I wonder what the real name is and what it does
Also:
- You can avoid the double \\ by using r-strings: r"C:\Users\MyID\OneDrive\Pictures\ScriptTest\", but forward slashes also work on Windows: "C:/Users/MyID/OneDrive/Pictures/ScriptTest/"
- The os.path module has a join method to create correct paths from directories and file names.
Thanks for the help.
There was nothing related to the Python interpreter in the security log.
I tried having it write to another disk (E://ScriptText/test1), but got the same error.
You're right about the MyID.
I caught the exception and this was the text:
Calling error for procedure 'file-png-save2':
Could not open 'C:/Users/MyID/OneDrive/Pictures/ScriptTest/test1' for writing: Permission denied
I checked the file permissions for the ScriptText and test1 folders, and they're both able to be written to.
I tried running the Python interpreter as Administrator, but still got that error.
Posts: 4
Threads: 1
Joined: Apr 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
(04-29-2023, 10:04 PM)Ofnuts Wrote: Nothing obvious, so:
- Check the system security log, perhaps the python interpreter is blacklisted and it (or its children) are not allowed to write to disk.
- If you catch the exception and print the exception message, you could have more info (see here for some hints)
- The OneDrive directory could have a special status, and this isn't difficult to check by writing elsewhere.
- I assume that MyId is replaced by the adequate username
- Your first name parameter has no extension, so I wonder what the real name is and what it does
Also:
- You can avoid the double \\ by using r-strings: r"C:\Users\MyID\OneDrive\Pictures\ScriptTest\", but forward slashes also work on Windows: "C:/Users/MyID/OneDrive/Pictures/ScriptTest/"
- The os.path module has a join method to create correct paths from directories and file names.
After some more experimenting, it looks like I've found a solution. It may not be the best solution, and feel free to tell me if it isn't, but it is at least *a* solution. I went into the "Properties" tab for the folder where the image was supposed to be saved and added write permissions for the "Guests" object. I guess either Gimp or Python was running as a guest.
Posts: 6,339
Threads: 272
Joined: Oct 2016
Reputation:
562
Operating system(s):
Gimp version: 2.10
Leonide
(04-29-2023, 10:04 PM)Ofnuts Wrote: Nothing obvious, so:
- Check the system security log, perhaps the python interpreter is blacklisted and it (or its children) are not allowed to write to disk.
- If you catch the exception and print the exception message, you could have more info (see here for some hints)
- The OneDrive directory could have a special status, and this isn't difficult to check by writing elsewhere.
- I assume that MyId is replaced by the adequate username
- Your first name parameter has no extension, so I wonder what the real name is and what it does
Also:
- You can avoid the double \\ by using r-strings: r"C:\Users\MyID\OneDrive\Pictures\ScriptTest\", but forward slashes also work on Windows: "C:/Users/MyID/OneDrive/Pictures/ScriptTest/"
- The os.path module has a join method to create correct paths from directories and file names.
After some more experimenting, it looks like I've found a solution. It may not be the best solution, and feel free to tell me if it isn't, but it is at least *a* solution. I went into the "Properties" tab for the folder where the image was supposed to be saved and added write permissions for the "Guests" object. I guess either Gimp or Python was running as a guest.
Weird. Next time you run your script, once its dialog is up, open the process/performance monitor (right-click the clock in the system tray) and check the id running the Python process. It should be your ID... (same as the Gimp process).
Posts: 4
Threads: 1
Joined: Apr 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
04-30-2023, 11:17 PM
(This post was last modified: 04-30-2023, 11:32 PM by Leonide.
Edit Reason: I'm a dumbass
)
(04-30-2023, 07:27 AM)Ofnuts Wrote: Leonide
(04-29-2023, 10:04 PM)Ofnuts Wrote: Nothing obvious, so:
- Check the system security log, perhaps the python interpreter is blacklisted and it (or its children) are not allowed to write to disk.
- If you catch the exception and print the exception message, you could have more info (see here for some hints)
- The OneDrive directory could have a special status, and this isn't difficult to check by writing elsewhere.
- I assume that MyId is replaced by the adequate username
- Your first name parameter has no extension, so I wonder what the real name is and what it does
Also:
- You can avoid the double \\ by using r-strings: r"C:\Users\MyID\OneDrive\Pictures\ScriptTest\", but forward slashes also work on Windows: "C:/Users/MyID/OneDrive/Pictures/ScriptTest/"
- The os.path module has a join method to create correct paths from directories and file names.
After some more experimenting, it looks like I've found a solution. It may not be the best solution, and feel free to tell me if it isn't, but it is at least *a* solution. I went into the "Properties" tab for the folder where the image was supposed to be saved and added write permissions for the "Guests" object. I guess either Gimp or Python was running as a guest.
Weird. Next time you run your script, once its dialog is up, open the process/performance monitor (right-click the clock in the system tray) and check the id running the Python process. It should be your ID... (same as the Gimp process).
Maybe I spoke too soon, as the error has come back. It was saving just fine, then I changed the script to use file_jpeg_save and gave the script a keyboard shortcut... and the error is back! I even tried giving Write permissions to the Everyone object, and it's still not getting permission to save.
According to task manager, both Gimp and Python are running under my ID.
I'm getting seriously frustrated, here. Why would it be working and then stop? I tried disabling my antivirus, thinking that might be blocking it, but no dice.
Edit:
....Aaaaand it's working again??? I think this time, I had the filename parameters wrong? Danged if I know, as long as it doesn't stop working again.
|