0

Python won't let me open this file. Why not? The format of the command is correct, and it's definitely a file that exists on disk.

Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, os.path
>>> path = os.path.join(os.getenv('LOCALAPPDATA'), r"Microsoft\WindowsApps\ilspy.exe")
>>> f = open(path, "rb")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument: 'C:\\Users\\<my name>\\AppData\\Local\\Microsoft\\WindowsApps\\ilspy.exe'
>>>
user3840170
  • 26,597
  • 4
  • 30
  • 62
Hammerite
  • 21,755
  • 6
  • 70
  • 91
  • 1
    Does this answer your question? [Python -How to solve OSError: \[Errno 22\] Invalid argument](https://stackoverflow.com/questions/63194917/python-how-to-solve-oserror-errno-22-invalid-argument) – 9769953 Jan 10 '23 at 11:35
  • What have you found searching on the actual error message? – 9769953 Jan 10 '23 at 11:35
  • 1
    WindowsApps is protected by the system. Generally, users cannot access it. It is not that python does not allow you to open it. – Mechanic Pig Jan 10 '23 at 11:35
  • 1
    @9769953, respectively: 1) there is nothing wrong with the format of the path. A path formatted in the same way successfully opens a file in another directory; 2) no it doesn't; 3) a load of other rubbish like the question you linked. – Hammerite Jan 10 '23 at 11:37
  • @Mechanic Pig, how may I evade this protection? This computer is my servant, not the other way around. I will not be told what I may and may not do on this computer, I won't have it. – Hammerite Jan 10 '23 at 11:40
  • 1
    Regardless of whether the computer is your servant or not, I think you can modify the problem properly so that people who know how to evade this protection will notice the problem. – Mechanic Pig Jan 10 '23 at 11:44
  • @MechanicPig, what do you suggest? – Hammerite Jan 10 '23 at 11:45
  • I haven't tried to bypass this protection. You can search for relevant information. I tried to find some, like [How to Access the Protected WindowsApps Folder on Windows](https://www.makeuseof.com/windows-access-windowsapps-folder/), which may be helpful to you. – Mechanic Pig Jan 10 '23 at 11:49
  • But here, the WindowsApp folder is located inside a Users folder. Shouldn't it normally be located inside the Program Files folder? Wouldn't it having it in the current folder automatically make it user readable? – 9769953 Jan 10 '23 at 11:55
  • 1
    @Hammerite no, your computer is not your servant. It's a device, and devices have to be safe. You can't format C: since the 2000s, or write to `Program Files`, precisely to prevent damaging the device and the applications on it. That's why `APPDATA` and `LOCALAPPDATA` exist. This prevented stupid developers from overwriting all your documents or desktop by deleting whatever the current folder was to "uninstall" it. Those developers tried to bypass this with elevated privileges which is why writes to protected folders are redirected now. – Panagiotis Kanavos Jan 10 '23 at 12:23
  • 1
    @Hammerite I'm not exaggerating either. I once had to help a friend that lost his entire PhD dissertation because a program "installed" itself on the desktop and just ... deleted the desktop when uninstalled. – Panagiotis Kanavos Jan 10 '23 at 12:25
  • 1
    @Hammerite in fact *you* don't want any old application reading your personal data stored by *another* application. You really don't want `CallOfDutyKeyGenerator` to read your tax returns for example, or the passwords stored locally in your password manager – Panagiotis Kanavos Jan 10 '23 at 12:25
  • 1
    But I do want Python to read this file - I'm telling the computer what to do here, not running malware or trashing the computer by mistake. Or if I am trashing it by mistake, it's my mistake to make. How do I let Python read this file? – Hammerite Jan 10 '23 at 12:57

0 Answers0