I have a Laravel app running on ubuntu 22.0.4. Inside one of my controllers I try to run a python script using shell_exec():
$output = shell_exec("python3 /home/ubuntu/test.py 2>&1");
Log::debug($output);
But the script is not executed and inside my log file I get:
"python3: can't open file '/home/ubuntu/test.py': [Errno 13] Permission denied"
I have set the permission for test.py to 777, and I have tried:
sudo chown ubuntu:www-data test.py
and also,
sudo chown ubuntu:ubuntu test.py
But still the same error. I have other projects running on ubuntu 20.0.4 with the same Laravel structure and logic in which I can execute the same python script (test.py) without any problem. But, for this specific case which I am using ubuntu 22.0.4, I am facing this problem. Also, same as other projects, I used pip3 to install python3.
Related
I need to run the laravel jobs in the background and for that reason, I need to run the supervisor on the Linux server.Whenever I try this
supervisorctl reread
It returns this error.
error: <class 'PermissionError'>, [Errno 13] Permission denied: file: /usr/lib/python3/dist-packages/supervisor/xmlrpc.py line: 560
I tried to change the permission of this file
chmod u+X /usr/lib/python3/dist-packages/supervisor/xmlrpc.py
It returns this error
chmod: changing permissions of '/usr/lib/python3/dist-packages/supervisor/xmlrpc.py': Operation not permitted
Any reason why it is not working? I recently upgraded the PHP to 8.1. Is this why it causing the problem?
I used to have the same problem as you, I used sudo at the beginning of the command and it worked fine
sudo supervisorctl reread
part of my python script is as below
panda_dataframe.to_csv("myfile.csv")
The code is working fine in my Dev System.
I have deployed it in EC2 - Ubuntu. The above statement return Server Error (500)
I have also tried with
panda_dataframe.to_csv("/usr/share/myfile.csv")
But the same error.
Error.log has the below error.
PermissionError: [Errno 13] Permission denied: '/usr/share/myfile.csv'
I have tried with setting the below permisions
sudo setfacl -m u:www-data:rw /var/www/sitefolder/myfile.csv
sudo setfacl -m g:www-data:rw /var/www/sitefolder/myfile.csv
Guide me what is the permission I have to assign to write the dataframe into a csv file
Your working directory is /usr/share, and saving/deleting/copy/move actions in /user directory requires sudo privileges. so first check you user directory by executing echo $HOME. say the result is /home/amir. now save you data frame as:
panda_dataframe.to_csv("/home/amir/myfile.csv")
I have a small service written in Python 3 which uses pysftp:
with pysftp.Connection(
host=host,
username=connection_data["user"],
port=connection_data["port"], log=log_file, cnopts=cnopts
) as srv:
…
and when I run it (python3 pythonprog.py) I get the following error:
PermissionError: [Errno 13] Permission denied: '/mydisk/folder/logs/pysftp-20181127-231208.log'
Obviously, I don't get this error if I run it with sudo python3 pythonprog.py.
I checked the permissions for this folder:
ls -l
drwxrwxrwx+ 2 myuser myuser 4096 Nov 27 22:38 logs
I also changed ACL with setfacl. Basically, whatever I do the error is still there. How can I grant this permission?
The service is running as someone -- that someone needs permission to write to that file or folder. This is not a code problem, its a permission problem. sudo is not the solution to running the code. I'm taking it that it is running as you? Can you write to that file/folder?
I'm trying to create a file inside a Django project on Amazon ElasticBeanstalk WebServer Environment. However it gives me a Permission Denied error.
Here is the error.
Traceback (most recent call last):
File "/opt/python/current/app/foo/boo.py", line 25, in create_file
input_file = open(input_filename, "w")
IOError: [Errno 13] Permission denied: 'testing.txt'
Thanks in advance!
If you want to create file on ElasticBeanstalk, you can, but you shouldn't, you have to use the amazon S3 service for that, with boto3.
But if it's just for a test you can add permisson with the .ebextensions file :
.ebextensions/instance.config
container_commands:
# Permisson on deploy command
0.0.0.files.chmod.ondeck:
command: "chmod u+xwr -R /opt/python/ondeck/app"
# Permisson on run dir
0.0.1.files.chmod.run:
command: "chmod u+xwr -R /opt/python/current/app"
I suggest you to create a folder in your app just for that. Than you can XX_permissions.config in your .ebextensions folder.
container_commands:
01_change_my_folder_permissions:
command: "mkdir -p /opt/python/current/app/my_folder; chmod 777 -R /opt/python/current/app/my_folder"
The command create the folder if doesn't exists and set the permissions. Just verify that your instance got the right permissions connecting directly using the ssh. Run the eb ssh [name-of-your-env] and check if the permission are ok:
ls -l /opt/python/current/app/
You should see your folder with a permission like drwxrwxrwx in the list.
This is an odd one.
We have a Jenkins server which runs fine for the most part, but fails on a python build. We run the build using invoke test, invoke being the python lib.
From what I can tell it is trying to run as root, or at least in the /root directory (n.b., not /, /root) which it doesn't have permission to do.
Here is the relevant line of the log:
IOError: [Errno 13] Permission denied: '/root/.invoke.yaml'
My question is why? and how do I stop it?
Here is the test command being run:
#task
def test():
# Install dependencies
install_requirements('dev-requirements.txt')
# Run tests
run("RUN_ENV=test nosetests --verbose --stop --with-xcoverage --with-xunit --cover-package=yt_api_auth --cover-inclusive")
# Test package generation
package_name, dist = get_names()
package()
run('pip install -U dist/{}.tar.gz'.format(dist))