WindowsError: [Error 5] Access is denied in Flask
<p>I am trying to move an uploaded file to a specific folder in my Windows system and it gives me WindowsError: [Error 5] Access is denied error. The solutions I happen to see for such problems are run python as Administrator from cmd line. I am not sure if that is possible since it's a web app and i am using the default flask server for development purpose .</p>

<p>my code is</p>

<pre><code>@app.route('/test',methods=['POST'])
def test():
    import os
    if not os.path.exists("history_plugin"):
        os.makedirs("test")
        f = open('test/abc.txt', 'w+')
        f.close()
</code></pre>

<p>Running the application 'directly in pycharm' is the equivlant of running it on the command prompt, but with a few caveats. <em>Personally I don't like running python in pycharm as I find it can cause errors.</em></p>

<p>Ideally you don't want to run as administrator, but you might find you have a couple of problems when it comes to windows. Firstly are you sure the Access Denied is from the file, and not from the trying to bind the app to port 80 (also note other issues with trying to bind on windows such as Skype taking over port 80)</p>

<p>If the problem is caused by the mkdir, make sure your user has permissions on the parent folder, not just the folder its creating. You are right to be wary of running as admin. Generally speaking you should create users per service and run as that, but it can be a pain during development (also, in 'production' you would want to run something like uwsgi or similar to act as a python process manager).</p>

<p>The other thing to note is that where you are running from - if you're running from your Desktop folder, I have noticed that this can also have strange permission problems for applications - but I'm assuming you're in a user 'workbench' folder of some kind.</p>

python flask