简体   繁体   中英

Error 13 Permission denied when trying to write on unrelated folder

I dont have much experience in python, so it might be a stupid question.

Im trying to write to a file in my script, if I run the script from his folder, it works, however if I run it from another folder, I have an error 13 persmission denied

ie in cmd :

cd C:\Users\user010\Perforce\Build\LS3\
py Build_jenkins.py

works but

cd C:\Program Files (x86)\Jenkins\workspace\LC3.3 Test\Qt\main
py C:\Users\user010\Perforce\Build\LS3\Build_jenkins.py

doesnt work. I have tried moving the script and the file to a public folder, same error :

Traceback (most recent call last):
  File "C:\Users\Public\Documents\Build\LS3\Build_jenkins.py", line 159, in <module>
    Variables.Sauvegarder()
  File "C:/Users/Public/Documents/Build/LS3/../Common\Variables.py", line 87, in Sauvegarder
    gArbre.write( NOM_FICHIER )
  File "C:\Python34\lib\xml\etree\ElementTree.py", line 761, in write
    with _get_writer(file_or_filename, encoding) as write:
  File "C:\Python34\lib\contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "C:\Python34\lib\xml\etree\ElementTree.py", line 798, in _get_writer
    errors="xmlcharrefreplace")
PermissionError: [Errno 13] Permission denied: 'Variables.xml'

The code is Variables.Sauvegarder() in my main file and in Variables :

import xml.etree.ElementTree as ET
gArbre = ET.parse( "Variables.xml" )
def Sauvegarder():
    gArbre.write( "Variables.xml")

Edit : important detail I forgot to mention, the file im writing to is located in the script folder (C:/Users/Public/Documents/Build/LS3/../Common\\Variables.xml)

老实说,我不确定Windows计算机(对于使用sudo的mac或其他基于Linux的系统),但是我建议尝试以管理员身份运行命令(使用runas命令以及名称)具有管理员权限的帐户。)这有望解决您遇到的错误。

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