Python Forum
PermissionError: [Errno 13] Permission denied: error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PermissionError: [Errno 13] Permission denied: error
#1
I know there is a few discussion PermissionError: [Errno 13] Permission denied: error in the forums but must admit I don't understand it.

I'm trying to use openpyxl (and selenium) to read from and write data to. However I'm not using excel(as i dont have it) so instead am using Libre Office Calc and saving the file as .xlsx

I get the following error PermissionError: [Errno 13] Permission denied: 'C://FireFoxProfile/login1.xlsx'[/python] (see the last line immediately below)

I would be super grateful for any advise or guidance

C:\Python37\python.exe C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py
test is passed
Traceback (most recent call last):
  File "C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py", line 31, in <module>
    XLUtils.writeData(path, "Sheet1", r, 3, "test passed")
  File "C:\Users\David\PycharmProjects\POM\XLUtils.py", line 22, in writeData
    workbook.save(file)
  File "C:\Python37\lib\site-packages\openpyxl\workbook\workbook.py", line 397, in save
    save_workbook(self, filename)
  File "C:\Python37\lib\site-packages\openpyxl\writer\excel.py", line 292, in save_workbook
    archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
  File "C:\Python37\lib\zipfile.py", line 1204, in __init__
    self.fp = io.open(file, filemode)
[b]PermissionError: [Errno 13] Permission denied: 'C://FireFoxProfile/login1.xlsx'[/b]
I've seen commentary that it needs to be stored in home directly? So currencly i have it in C://FireFoxProfile/ does this mean i need to move the file to C://Python37 (where i have python.exe?)

I've also see commentary about needing to run it as system administrator??

Here is my code - the line of interest i path = "C://FireFoxProfile/login1.xlsx" which is found in the DataDrivenTestCase Module

Module XLUtils

import openpyxl

def getRowCount(file, sheetName):
    workbook = openpyxl.load_workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    return(sheet.max_row)

def getColumnCount(file, sheetName):
    workbook = openpyxl.load.workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    return(sheet.max_column)

def readData(file, sheetName, rownum, columnno):
    workbook = openpyxl.load_workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    return sheet.cell(row = rownum, column = columnno).value

def writeData(file, sheetName, rownum, columnno, data):
    workbook = openpyxl.load_workbook(file)
    sheet = workbook.get_sheet_by_name(sheetName)
    sheet.cell(row=rownum, column=columnno).value = data
    workbook.save(file)
Module DataDrivenTestCase

from selenium import webdriver
import unittest
import XLUtils

profile_path = 'C:/FireFoxProfile'
profile = webdriver.FirefoxProfile(profile_path)
driver = webdriver.Firefox(firefox_profile=profile_path)
driver.implicitly_wait(5)
driver.get('http://www.demoaut.com/')
driver.maximize_window()

[b]path = "C://FireFoxProfile/login1.xlsx"[/b]

rows = XLUtils.getRowCount(path, 'Sheet1')

for r in range(2, rows):
    username = XLUtils.readData(path, "Sheet1", r, 1)
    password = XLUtils.readData(path, "Sheet1", r, 2)

    driver.find_element_by_name("userName").send_keys(username)
    driver.find_element_by_name("password").send_keys(password)

    driver.find_element_by_name("login").click()

    if driver.title == "Find a Flight: Mercury Tours:":
        print("test is passed")
        XLUtils.writeData(path, "Sheet1", r, 3, "test passed")
    else:
        print("test failed")
        XLUtils.writeData(path, "Sheet1", r, 3, "test failed")

    driver.find_element_by_link_text("Home").click()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

if __name__ == '__main__':
    unittest.main(verbosity=2)
Reply
#2
Permission denied is an Operating System error, not related to python.
path = "C://FireFoxProfile/login1.xlsx"
My guess is that the firefox directory that you are trying to save in has not given you permission to write.
Add write permission, or choose another directory.

Quote:does this mean i need to move the file to C://Python37 (where i have python.exe?)
No, you shouldn't be storing files directly to this directory. It should be maintained by pip or other
package software.

Quote:I've also see commentary about needing to run it as system administrator??
That may work, but is this what you want a user to have to do?
Reply
#3
OK - i'm trying to give permission to the folder.

I'm the only person that uses this laptop. I'm logged in with user = David which is part of the administrator group.

So i've gone into C://FireFoxProfile/login1.xlsx in file directory. Right clicked on it / properties / security

I've edited / added so i have the following

[Image: 14ugspk.jpg]

I'm still getting the exact same error message....am i missing or not understanding something?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 230 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  KivyMD android app - problem with permission polak7gt 0 275 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 695 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 1,004 Aug-09-2023, 01:24 PM
Last Post: erg
  The INSERT permission was denied on the object Steven5055 2 1,472 Feb-25-2023, 11:37 PM
Last Post: Steven5055
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,778 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,113 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 9,706 Feb-05-2022, 06:14 PM
Last Post: snippsat
  Error no 13: Permission denied in python shantanu97 1 6,150 Mar-31-2021, 02:15 PM
Last Post: snippsat
  Access denied not able to do anything 8( What do i do? MurphysLaw 3 3,746 Oct-20-2020, 08:16 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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