Home > Back-end >  During handling of the above exception ([Errno 13] Permission denied: 'new1234567.csv'), a
During handling of the above exception ([Errno 13] Permission denied: 'new1234567.csv'), a

Time:11-16

I am trying to create a csv file using pandas in the AWS EC2 instance(Linux OS) using the below code.

import pandas as pd
df = pd.DataFrame(listlead)
df.to_csv('new1234567.csv')

I am getting an error 'Permission denied' from the server. But when I run it on the local system(Windows OS) it was working fine.

I try to change the name of the file but the error continues to exist. I try to delete the file but it said file does not exist. Can someone give me a solution for this problem and tell why it is happening?

CodePudding user response:

It seems like you don't have permission to create a csv file in the folder you're working in, on the server.

When you rundf.to_csv('new1234567.csv'), it looks for a file named new1234567.csv inside the current directory, and if it doesn't exists, it tries creates it - which is also the reason you're not able to delete it: it doesn't let you create it in first place.

Go with a terminal inside the working directory in which you're trying to create the file (same directory of your script, in this case), and run sudo chmod 700 . This will add read, write and execute permissions to the current user only.

Now your script should be able to create, read and write new files in the directory.

  • Related