Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Noob seeks Help with shutil Permissions Error
-
Hey all!
This is my first time using the Pythonista App, and pretty much my first time coding in Python so I’m kind of coming at this with zero knowledge other than some general coding experience.
Anyway, I just recently set up a local SMB server and thought it would be cool to try out either Pythonista or scriptable to easily copy Local iPad files over to my server. I had some issues with scriptable so here I am :)
I used appex.get_file_url() to get a file path for testing, and am just plugging it in to shutil copyfile() to get a demo of copy/paste functionality, but I’m being met with a permissions error!
Here’s my code
import ui, appex, clipboard, shutil # filePath = appex.get_file_path() filePath = '/private/var/mobile/Containers/Shared/AppGroup/*long string idk if its sensitive so removed*/File Provider Storage/debug.log' testdst = '/private/var/mobile/Containers/Shared/AppGroup/*long string idk if its sensitive so removed*/File Provider Storage/debugcopy.log' shutil.copyfile(filePath, testdst)
On running this, I get the following error:
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/*longstring*/Pythonista3/Documents/copypastefile.py", line 9, in <module> shutil.copyfile(filePath, testdst) File "/var/containers/Bundle/Application/*longstring*/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/shutil.py", line 121, in copyfile with open(src, 'rb') as fsrc: PermissionError: [Errno 1] Operation not permitted: '/private/var/mobile/Containers/Shared/AppGroup/* long sting */File Provider Storage/debug.log'
Is this just a limitation of Pythonista (no access to files app)? Do I need to reformat the file paths? I literally just copy pasted the output of my test get_file_path() call which I ran through the “run Pythonista script” option after selecting a file I had sitting in the files app.
Anyways, I’ve been on a real DIY kick lately and I’m hoping I can integrate Pythonista and learn a bit of a new language along the way!
Thanks for any help
-
@itsseanl You have to define (only once) access to File Provider Storage folder in Pythonista/External Files/Open/Folder and it will work.
Anyway, welcome here
-
@cvp amazing! Thanks so much. I’m blown away every day by the cool things I’m discovering that I can do from the iPad
-
@cvp As a follow up to this, it ran fine with the pre-defined file paths when I ran it within Pythonista, but I still get a permission error when I try to run it from the files app itself as a shortcut. Can these kinds of operations only be done from within the Pythonista app?
-
@itsseanl is the permission error given for the from-file or for the to-file?
-
@itsseanl I've a similar program but copying to a local Pythonista file, without error
-
everything works for me too. try as a crutch
with open(testdst, 'x') as testdst, open(filePath,'r') as filePath: testdst.write(filePath.read())
if it does not work, then most likely you do not have write access in this directory