My Python program uses the terminal(system) command to perform the task on the file and script. I am going to convert this Python program into Mac OS application and Linux application using pyinstaller. I am going to pass the application installer file to my friends. However, I have following questions.
If script or file doesn't have proper permission which my program is trying to access, will Python get an error?
Running some script or opening file will require the permission of root. So is there a possible option that will prompt the user for root(admin) password or run my application with root privilege?
Thanks
Try chmod 777 filname.py, this will give the file all rights for execution and editing. There are also other modes for chmod like 755, which will also work for your case.
Related
I'm working on MAC application contains a command line tool.
The GUI (electron) using sudo prompt to run the command line tool written in Python.
Under Catalina, the app all needed permission to w/r for the protected directories like Desktop with no issue.
Needed permission request were added to plist and it is signed with list of entitlements.
All works well except accessing external hard drive. Any try to create folder or modifying its properties using chmod command for example return with permission denied.
Just for note, calling same command from terminal ends well with no issue
Any ideas how I can go over it?
How App can request Full disk access?
I have installed Tomcat in my system and when I type "http://localhost:8081/"
I get the following screen
However when I try to run a .py file from Tomcat, it is unable to interpret the file and shows me the following screen. What should I do to resolve this issue?
Tomcat doesn't know how to run Python scripts without additional configuration. You need to configure Tomcat's CGIServlet in order to run Python scripts.
I have installed ffmpeg in my server running ubuntu 14. my flask app project root is at /var/www/project/
i am able to upload files and my python scripts are able to write new files, but when i run ffmpeg in my script it gives permission denied.
Also running the below line in terminal
ffmpeg -i path/to/inputfile /path/to/outputfile & ps aux | grep ffmpeg
gives the user running the process is "ubuntu" which has write access to the project folder and its subfolders. As i told you other python script run by user "ubuntu" is able to create file.
permission denied error happens in both cases(python script and directly in terminal)
update:
also looking at the confusion with the permissions, is there a way i can run the app from /home/ubuntu/project instead of /var/www/project. i am using mod_wsgi with apache for my flask-app.
right now i have added sudo and it is working fine, though i am not sure running ffmpeg as sudo would cause any security issue. Anyone please clarify on this.
cmd='sudo ffmpeg -i '+f_name+' -acodec '+job['audio_ff']+' -b:a '+job['audio_bps']+'k - b:v '+job['video_bps']+'k -s '+job['res_width']+'x'+job['res_height']+' '+new_file
p=subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE)
The files which are created by your app resides in the var/www/project and these need administrative privilege, if you want to read/access them. Without using sudo you cannot access the administrative protected files.
You can change the rights of the files created by your app to be accessed by ffmpeg without sudo or change the ownership to your username with chown..
Have you checked if your ffmpeg executables have permissions for all the users?
I have stabled password less login between two ubuntu system then I run following command
$scp file user#hostname2:/tmp/
it works fine and I got file transferred without asking for password.
however when I try to execute the same through following python statement-
subprocess.check_output(['scp', file, r'user#hostname2:/tmp/'])
I am not able to copy files to remote computer, so I am bit curious about which user's privileges python program uses to execute command via subprocess ?
How can I debug such programs ?
I have an app on my website, and I run it with Python from the Windows Command Prompt.
When I try opening it like this,
python http://www.erickwilts.nl/apps/app.py
it says:
python: can't open file 'http://www.erickwilts.nl/apps/app.py': [Errno 22] Invalid argument
Is there a way I can do this?
Since the resource is located on webserver, you must download it first.
You can do it with urllib2
import urllib2
exec(urllib2.urlopen("http://www.erickwilts.nl/apps/app.py").read())
executing scripts like this is really dangerous though.
What I really wanted is to execute the file on the webserver itself. Luckily, I had help from some more experienced guys, who helped me on installing python on the webserver en executing my script from my own computer using ssh.