PermissionError: [Errno 1] for os.rename as quick action - python

This question represents the latest issue encountered when solving another problem. Let me explain the current issue first and leave the initial difficult at the end.
os.rename(old_path, new_path)
This Python command works when running the Python script in Automator (using the the run button on the top right).
/usr/local/bin/python3 "/Users/user/Library/Scripts/move.py"
However, when run as a quick action, it throws the error
The action “Run Shell Script” encountered an error: “Traceback (most recent call last):
File "/Users/user/Library/Scripts/move.py", line 6, in <module>
os.rename(folder_path, folder_nath)
PermissionError: [Errno 1] Operation not permitted:
All suggested solution tell me to grant various programmes full disk access. However, after having done so for Terminal, Finder, Automator and bash, I still see the error. I even changed the permissions for the folder to be renamed in the 'Get info' box. Nothing has helped.
This problems seems to be isomorphic with a problem I had earlier with another commend not working as a quick action:
os.system("""/bin/mv \"""" + old_path + """\" \"""" + new_path + """\"""")
This command works in PyCharm; it works when I run the python code containing it in Automator (using the Run button in the top right).
/usr/local/bin/python3 "/Users/user/Library/Scripts/move.py"
However, it does not work when I run this workflow as a quick action triggered by a keyboard short-cut: the quick action clearly works as the little cog rotates, but the file remains unchanged.

I have solved this issue. When it comes to quick actions like this, you need to grant full disk-access permission to the application open when you use the quick action.
As I use this quick action when using, for example, TextEdit, I needed to give TextEdit full disk-access permission.

Related

Cannot get Perforce Triggers to work properly

Been trying to get this working all day, and i just can't figure out why its not working.
Trying to implement a simple trigger to run when the user submitted a file.
example in the .tmp file:
hello_trigger change-submit //testDepot/... "python F:/triggers/hello_trigger.py"
when i try to submit a file i get this:
Submit validation failed -- fix problems then use 'p4 submit -c 10199'.
'hello_trigger' validation failed: python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
File exists and can be read, so its not a python issue.. same error with a .txt or .bat file.
From what i can gather the problem seems to be coming from the depot line in the trigger.
//testDepot/... fails
//depot/... doesnt fail, but the script is never fired off.
Any suggestions are greatly appreciated.
also testDepot is a stream not sure if that matters.
python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
seems pretty clear that the file doesn't exist, at least from the point of view of this trigger command. Some things to double check:
This is running on the server machine, i.e. the place where the p4d service is running. If you have the script on your client machine the Python executable on the server isn't going to be able to find it!
Similarly, this is being run by whatever user is running p4d (on Windows this is usually the SYSTEM user, which may have limited permissions). Does that user have permission to read this path?
Could it be that your version of Python on Windows doesn't know how to handle paths with Unix-style forward slashes? (Many tools will normalize these for you but you shouldn't depend on it!) Try using a valid Windows path, i.e. F:\triggers\hello_trigger.py.

Trying to run a code I wrote myself on my Terminal, the result: Permission denied

I wrote some code on my laptop and now I am trying to run this code. But it give me the output : Permission denied
Usually that should only happen if a different user would try to access it. But I am the user who wrote it and is trying to run it now. I feel like this will be an easy issue to resolve but any help would be nice! Thanks.
I wrote and saved the code in IDLE python. Once I finished I tried running it in my Terminal (I have the macOS Mojave Version 10.14.5) but then I ran into the issue.
Evandros-MBP:~ evandro$ ./Desktop/FunCodes/pwd.py
This is how I tried to call up the code. I don't see any issues here.
Instead of calling the script with
./Desktop/FunCodes/pwd.py
try using
python ./Desktop/FunCodes/pwd.py
or also
python3 ./Desktop/FunCodes/pwd.py
if you want to execute it with python3 instead of python2.
Explanation
When you write ./some-file in the terminal (without writing python before the file path), the terminal executes it as a bash file (no matter if the file has a .sh extension or not). Of course, since your file is a python file, this will fail. But even before it fails, since your python file has no permission to be executed, permission will be denied and bash won't even start.
On creation, the file only has read and write permissions. Add a shebang pointing to the Python interpreter on the script's first line, for example #!/usr/bin/env python. Also, your script is not marked as executable, in order to do that you need to use:
chmod +x pwd.py
Otherwise you will only be able to run it with Python, with
python pwd.py

Getting a "The process failed to start (invalid command?). (1)" error when starting up Pyzo

I recently booted up my Pyzo IDE with the intention of doing some programming, however, upon starting up the python shell it gave this following error:
The given path was not found
The process failed to start (invalid command?). (1)
I am not able to run any code with this error. If I try to run it nothing happens and the error re-appears.
I have tried reinstalling the whole thing without success, I have tried reading the log but there was no error message and I have also tried looking for posts regarding the same problem without success. I was hoping if someone could explain what my problem is and a possible solution, thanks.
This is how I fixed it:
I went to miniconda3 file in C:\Users\<user>\Miniconda3 (might be in other file/the thing is you need to find the miniconda3 file)
Find the Python application
Rename it to "python.exe"
Then go to shell configuration and replace the path to the operable python program in "exe" with your path (for me it was
C:\Users\<user>\Miniconda3\python.exe)
For me the solution was much simpler than the solution proposed.
I had misspelled the path to python.exe
Go to Shell tab
Press the button that says Python and has a small arrow at the right bottom
After pressing the button a drop-menu will appear. In this meanu choose Edit shell configurations ...
A new window will open. In this window put the correct path in the exe field
The path for me (windows 7) was c:\users\user\appdata\local\programs\python\python38\python.exe. For other users might be different

Python - Creating a file works in PyScriptor but not IDE?

When I try to create a new file in PyScriptor using the following code, it works perfectly with no errors but when I use the same code outside of PyScriptor for example in the IDE, it just flashes an error and closes.
file = open("file.txt", "w")
file.write("hello")
file.close()
I cannot get the errors because the error message lasts for less than a second before the Interpreter closes.
Help to figure out why this happens and how to fix it is appreciated.
I am using Python version 2.5.3.0 on windows 7 if this helps.
[EDIT]
Thanks to kirbyfan64sos and JAB for helping me get the errors. It turns out that Python does not have permission to open any file at all (r, w, a etc) yet Pyscriptor has all these permissions so the question still remains: why are they be different and how do i fix them?
I know that it is not the permissions of the file itself otherwise it would not work in Pyscriptor.
[ERROR CODE]
Traceback (most recent call last):
File "IDE File test.py", line 1, in <module>
file = open("file.txt", "w")
IOError: [Errno 13] Permission denied: "file.txt"
Use "w" instead of "W". "W" is an invalid file mode. Also, file.close should be file.close(), as file.close will just return the file object's close method and won't actually call it.
Note that if you start the interpreter from inside the command shell, the shell won't close when an error is raised so you'll be able to see it there. The same applies to using IDLE.
Chances are the permissions of wherever your IDE is running in are not writable by you.
To check:
import os
print(os.path.abspath(os.curdir))
I'm quite certain that you'll find the current path will be different depending on which IDE you run from. Most IDEs have a setting for which path you'll start at. You can also get around that by using os.chdir to change to your home directory (or giving an absolute path to open(), e.g. open('/home/wayne/test.txt', 'w'))

fuse-python xmp.py - Not able to create a file

I am writing a Network File System, and I have started by trying to understand the xmp.py provided with python-fuse.
Well basically I'm sending all the calls over the network, executing it on the server-side and sending the result to the client and returning it to the user. These parts are working perfectly fine.
The problem I am facing is that, the xmp.py is not able to create a file and hence the problem is showing up in my Network File System too.
The steps I have followed are:
Installed fuse-python by:
sudo apt-get install python-fuse
Then I go into the directory where xmp.py is located:
cd /usr/share/doc/python-fuse/examples/
I ran the xmp.py program with the following command-line arguments
python xmp.py -o root=/home/user /tmp/fuse
where /home/user will be replicated or mounted on /tmp/fuse
Then I cd into the /tmp/fuse directory and try to make a file with cat, like:
cd /tmp/fuse
cat > temp.txt
I get the error
bash: temp.txt: Invalid argument
After a lot of poking around, I believe that this is due to the function
def getattr(self, path):
return os.lstat("." + path)
When I do a cat > temp.txt, os.lstat("./temp.txt") is called and an error is thrown as the file /home/user/temp.txt is not found. After this the program gets stuck for a while and slows down my computer.
Please help me figure out what I'm doing wrong.
Thanks.
I think i have figured it out, the problem that i saw was once os.lstat("./temp.txt") fails, the file class's __init__ method is called and then immediately truncate is called and the program returns.
One solution that i followed was to not use the file class at all, and to implement the Fuse class' open/create to make the file.
This approach worked for me. If anyone has a better suggestion please let me know. I would like to use the object-oriented approach and use the file class.

Categories

Resources