简体   繁体   中英

from “PermissionError: [Errno 13] Permission denied:” to “PermissionError: [WinError 5] Accès refusé:”

When I run this code:

def register_json(path, _dict):
    from json import dump
    with open(path, 'w') as f:
        dump(_dict, f)

json_path = "C:\Program Files (x86)\RT Forms\debug.json"
my_new_dict = {"yolo":"swag"}
register_json(json_path, my_new_dict)

I get this error message: PermissionError: [Errno 13] Permission denied: 'C:\\Program Files (x86)\\RT Forms\\debug.json'

So I tried to change the rights of my file:

from os import chmod
json_path = "C:\Program Files (x86)\RT Forms\debug.json"
chmod(json_path, 0o777)

and now I get this error: PermissionError: [WinError 5] Accès refusé: 'C:\\Program Files (x86)\\RT Forms\\debug.json'

Is there a solution to give the right during the creation of the file maybe? (Yes, I am the one who create the file, the entire folder with pyinstaller and HM NSIS edit to have a.nsi which create this folder. When you execute the.exe it will create the.json file).

Thanks to @viilpe, I am registering data in C:\\ProgramData now. (it could have been AppData).

So it was just a permission problem from C:\\Program Files (x86)\\ folder, don't try to change something in it after the installation of your application because you had the administrator rights, you won't have it anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM