python open() - access denied

我怕爱的太早我们不能终老 提交于 2021-02-20 19:36:13

问题


This is my first post on stackoverflow, so if somethings wrong I'm eager to learn!

I'm programming a plugin for Cinema 4d with python. Everything works on Mac, but I'm having problems on Windows with what I'm about to explain.

The plugin needs a path to a server, in case of rendering on a renderserver. I want the user to enter the path once, and to then store it in a .txt file.

for c4d, plugins are being installed, by draging-and-droping the plugin into the plugin folder at for example:

C:/programm files/Maxon/Cinema4D/Plugins/NewPluginGoesHere

In Order to keep everything nice and clean, I want the pathToServer.txt (text file that only stores one line with the path) in the plugin folder as well. When Installing (droping) the plugin into said folder, the .txt file is already there -> Not created by the plugin.

Here comes the problem:

I open and write to the file with

pathFile = open(pathToPathFile, "w")
pathFile.write(pathToServerFolder)

Works fine on mac, but throws

IOError: [Errno 13] Permission denied: 'C:\\Program Files\\MAXON\\CINEMA 4D R14\\plugins\\MultiLayerRender\\Renderserverpath.txt'

on Windows.

I'm pretty inexperienced with using python for such tasks (like file management).

I then tried the following:

pathFile = subprocess.Popen(pathToPathFile, stdin = subprocess.PIPE, stdout = subprocess.PIPE, shell = True)
pathFile.communicate(input = pathToServerFolder)
pathFile.stdin.close()

Which doesn't give me an error, but it also doesn't seem to do anything :/

I read throung the python documentation of subprocess, but that realy didn't help me at all, if anything, it confused me.

I noticed, that I also need to run my code editor in Admin Mode, in order for it to have permission to save directly into the plugin folder in said directory. It seems like files in the 'program files' folder are somehow protected. Also, this plugin will be installed on several different computers either mac or windows, and therefor changing permission on for example the programm files folder is not an option. In the end draging and droping should be all one has to do in order to install it.

Does anyone know how to achieve that?


回答1:


You need elevated permissions to write to Program Files on Windows, somehow your plugin does not have them. I would consider just using another directory.

Many render solutions requires you to specify a directory somewhere, so I don't think it's a huge problem. modo 501 and 601 (and 701 presumably), for example needs a directory somewhere for data sharing. V-Ray for Maya more or less requires you to put the scene files on a shared drive in distributed mode.



来源:https://stackoverflow.com/questions/15990843/python-open-access-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!