Search code examples
pythonpopen

How to catch Permission Error with Popen process


This is the error: Permission Error: Copying of text from this document is not allowed.

I am opening a .exe file on windows. So regular try except block does not seem to catch it. Neither does OSError.


Solution

  • I solved it with the following:

    try:
        """code here"""
    except subprocess.CalledProcessError:
        """unlock files and try again"""