Python Forum
PermissionError: [Errno 13] Permission denied: error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: PermissionError: [Errno 13] Permission denied: error (/thread-17661.html)



PermissionError: [Errno 13] Permission denied: error - leviathan54 - Apr-19-2019

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)



RE: PermissionError: [Errno 13] Permission denied: error - Larz60+ - Apr-19-2019

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?


RE: PermissionError: [Errno 13] Permission denied: error - leviathan54 - Apr-20-2019

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?