How to fix [Errno 13] Permission denied with openpyxl

jeepers mcface

Inspired by Automate the Boring Stuff with Python, I am doing just that! Everything seems to be going well until I try to save the workbooks I edit with openpyxl. I get an error only at that point in the code.

Here is the relevant part of the code (before this I use selenium to download the appropriate file):

#Gets list of files from downloads
list_of_files = glob.glob('PATH/TO/DOWNLOADS/*')

#Finds most recently downloaded file
latest_file = max(list_of_files, key=os.path.getctime)

#Gets path to destination for sheet in downloaded spreadsheet
report = r'PATH/TO/DESTINATION'

#Appends r to string of latest_file path so that it can be read
pyxlOpen = r'%s' % latest_file

#Opens recently downloaded file as workbook object
snapshotWB = xl.load_workbook(pyxlOpen)

#Gets only sheet in the spreadsheet and renames it 'Snapshot'
snapSheet = snapshotWB.worksheets[0]
snapSheet.title = 'Snapshot'

#Opens destination workbook as workbook object 
reportWB = xl.load_workbook("report")


#Gets rid of any old Snapshot sheet if it's in there
if 'Snapshot' in reportWB.sheetnames:
    del reportWB['Snapshot']

#And add in the new one!
newSnapSheet = reportWB.create_sheet("Snapshot")
for row in snapSheet:
    for cell in row:
        newSnapSheet[cell.coordinate].value = cell.value

#Saves the workbooks!
snapshotWB.save(filename = 'latest_file')
reportWB.save(filename = "Practice.xlsm")

I tried to just do paths instead of variables just to test it, and that didn't work either. But the paths must be accurate, or else I couldn't create a workbook object out of them--right? I also tried switching the order of my saving lines just to make sure that one of the workbooks wasn't the problem child. They both are.

anand_v.singh

You are trying to create a file and your OS is saying you that your program does not have the permission to write to that directory. You should specify the full path of the file you're trying to create. If it still fails, comment below and we will see.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Python - IOError: [Errno 13] Permission denied:

OSError - Errno 13 Permission denied

Errno 13 Permission denied using Gunicorn

IOError: [Errno 13] Permission denied

PyCharm error: [Errno 13] Permission denied

Python [Errno 13] Permission denied:

Errno 13 Permission denied Python

phpmyadmin site on macOSSierra errno: 13 - Permission denied

How can I fix "PermissionError: [Errno 13] Permission denied: 'static'"?

PermissionError Errno 13 Permission denied

permission denied in apache configuration : [Errno 13] Permission denied

Errno 13 Permission denied when running virtualenv

How to solve, PermissionError: [Errno 13] Permission denied: 'test.from'

HOW to fix 'PermissionError: [Errno 13] Permission denied' in python-crontab in docker image?

How to solve OS Error: Permission denied, errno = 13 in flutter

Python Errno13 Permission Denied

pip install - PermissionError: [Errno 13] Permission denied

Apache: Errno 13 file permission denied

DASK : IOError: [Errno 13] Permission denied:

django error logging : [Errno 13] Permission denied

"Errno 13 Permission denied" for pip and anaconda

cassandra copy [Errno 13] Permission denied

How to fix [Errno13] permission denied when trying to read excel file?

BlueData MLOPS - PermissionError: [Errno 13] Permission denied

Errno 13 Permission denied for downloading files

How can I fix "[Errno 13] Permission denied: '_cmp.pyi'" in my Python nix flake?

PermissionError: [Errno 13] Permission denied in python project

Linux [Errno 13] Permission denied

Linux [Errno 13] Permission denied