-1

this is the code I'm trying to run in python 3.10:

def copyComplete(source, target):
    shutil.copy2(source, target)
    st = os.stat(source)
    os.chown(target, st.st_uid, st.st_gid)

It throws this error:

AttributeError: module 'os' has no attribute 'chown'

How do I fix this problem?

  • 3
    What OS are you on? The `chown` function is documented as Unix-specific: https://docs.python.org/3/library/os.html#os.chown https://docs.python.org/3/library/intro.html#notes-on-availability – slothrop Aug 04 '23 at 16:43
  • `copy2()` should already preserve file ownership. – jordanm Aug 04 '23 at 16:46
  • I'm in windows, but the file I'm trying to copy doesn't let me write/append using *python code* with open('examplefile.json', 'a') as file: file.append('etc.')*exiting python code*, but instead throws permission error – Indeterminable Aug 04 '23 at 17:03
  • This answer might be helpful; [PermissionError: Errno 13 Permission denied](https://stackoverflow.com/a/36469464/8658598). – doneforaiur Aug 04 '23 at 17:54

1 Answers1

0

os.chown doesnt exist for windows

you need to use something like

  • another python package link

  • use windows takeown.exe doc

  • win32security lib see this

Ruslan
  • 444
  • 3
  • 8