'Running a python script that reads folders ends up with "Winerror 5: Access is denied." I already tried running as admin

The program is written in Python, specifically the folder that I'm trying to read is chosen using PyQt5's QFileDialog. The process used to work flawlessly but something changed, and I have no idea how to check.

Now I keep getting Error in opening file: [WinError 5] Access is denied: whenever I try to open literally any folder using that program. I just read the folders, I make do any changes to it.

I used a conda env to develop the program. I tried to create a new conda env, no luck. I tried re-creating the environment using poetry, still same. I tried using an admin powershell using both conda and poetry, still the same error.

I tried moving to another computer, tried conda and poetry and admin, still nothing.

I also tried resetting the permissions of all the files (both the folders I'm trying to open and the code for the program itself) using icacls "FOLDER" /reset /t /c /l, same error.

It used to work just fine until last week when this started to happen, and I haven't even made any changes to the file loader code since then (I was working on another part of the program).


Might be related: part of my script involves copying a file from one location to another. I'm just using shutil.copy(Path(str(Path(__file__).parent) + r'\default_config.ini'), config_file_path) (the paths are correct, I checked), but the copied file comes out blank. I also tried shutil.copyfile, same behavior.



Solution 1:[1]

Use Process Monitor, add a filter for Python and check where the access problem occurs.

Maybe you put that filename into a variable and inspect it in a debugger instead of using it directly in the copy command. From the description it looks as if you concatenate Paths using /, not +.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thomas Weller