Server Error while saving panda dataframe to csv - python

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")

Related

xmlrpc.py permission denied whole running the supervisor

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

python3 [Errno 13] Permission denied

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.

pysftp can't create log file - permission denied

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?

Cannot create file inside Python on Amazon ElasticBeanstalk

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.

Chmod in Python - [Errno 1] Operation not permitted

I'm trying to modify an application in my /Applications folder on OS X. I need to get read and write permissions, so I currently have:
os.chmod(appDir, 0644)
where appDir is the directory of my app. However, whenever I run the program, I get the error:
OSError: [Errno 1] Operation not permitted: '/Applications/Simplenote.app'
I would try sudo, but how would you enter the password through Python? (this is a Python script by the way)
Any help is appreciated.
If you are trying to run the script from a web site, change the target folders/files to be owned by the web user, e.g. www-data. sudo chown www-data * -R That fixed it for me.

Categories

Resources