Python Forum
Error no 13: Permission denied in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error no 13: Permission denied in python
#1
written a python code for converting excel to csv code. run code in c and g drive. error is coming.

#Purpose: '''This python script is to extract each sheet in an Excel workbook as a new csv file'''
#Usage:  python ExceltoCSV.py [Excel_File_Location] [CSV_File_Location] 
#		  [C:\Users\....\Input_File.xlsx] [C:\Users\....\Output_Folder_Name/] Remember to put Forward Slash After Output Folder Name to save CSV file

import csv
import xlrd
import sys

def ExceltoCSV(excel_file, csv_file_base_path):
    workbook = xlrd.open_workbook(excel_file)
    for sheet_name in workbook.sheet_names():
        print('processing - ' + sheet_name)
        worksheet = workbook.sheet_by_name(sheet_name)
        csv_file_full_path = csv_file_base_path + sheet_name.lower().replace(" - ", "_").replace(" ","_") + '.csv'
        csvfile = open(csv_file_full_path, 'w',newline='')
        writetocsv = csv.writer(csvfile, quoting = csv.QUOTE_ALL)
        for rownum in range(worksheet.nrows):
            if rownum == 0:
                writetocsv.writerow(
                    list(str(x) for x in worksheet.row_values(rownum))+["SourceFile"]      
            )   
            else:    
                writetocsv.writerow(
                    list(str(x) for x in worksheet.row_values(rownum))+[excel_file.split("\\")[-1]]      
                )          
        csvfile.close()
        
if __name__ == '__main__':
    ExceltoCSV(excel_file = sys.argv[1], csv_file_base_path = sys.argv[2])
it will show error.
Error:
File "ExceltoCSV.py", line 29, in <module> ExceltoCSV(excel_file = sys.argv[1], csv_file_base_path = sys.argv[2]) File "ExceltoCSV.py", line 10, in ExceltoCSV workbook = xlrd.open_workbook(excel_file) File "C:\Users\ShantanuGupta\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd\__init__.py", line 111, in open_workbook with open(filename, "rb") as f: PermissionError: [Errno 13] Permission denied: 'G:\\TestFilesIn'
Reply
#2
(Mar-31-2021, 11:02 AM)shantanu97 Wrote: [Errno 13] Permission denied: 'G:\\TestFilesIn'
Look like you try to open a folder and not file.
So if file was in that folder argv from command line would be G:\TestFilesIn\some_file.csv.

Just to show an other way as Pandas already has this feature build with DataFrame.to_csv
Notebook Example
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  KivyMD android app - problem with permission polak7gt 0 299 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 729 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 1,053 Aug-09-2023, 01:24 PM
Last Post: erg
  The INSERT permission was denied on the object Steven5055 2 1,493 Feb-25-2023, 11:37 PM
Last Post: Steven5055
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,822 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,136 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 9,872 Feb-05-2022, 06:14 PM
Last Post: snippsat
  Access denied not able to do anything 8( What do i do? MurphysLaw 3 3,786 Oct-20-2020, 08:16 AM
Last Post: snippsat
  How a Mac OS software can restart itself with admin permission in Python 3.7? Formationgrowthhacking 0 1,790 Sep-03-2020, 05:29 PM
Last Post: Formationgrowthhacking
  os.remove() Access is denied pythonnewbie138 3 30,983 Aug-28-2020, 10:02 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020