1

I'm running an apache2 server with flask and mod_wsgi.

In my flask script I have a function that creates new directories:

def updateDir():
    dbData = News.query.all()
    for row in dbData:
        rowLink = createLink(row.id, row.title)
        finalPath = "static/img/posts/{}".format(rowLink)
        os.makedirs(finalPath, exist_ok=True)

When I try to run the script it shows this traceback:

ERROR in app: Exception on /refresh [GET]
 Traceback (most recent call last):
   File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
     response = self.full_dispatch_request()
   File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
     rv = self.handle_user_exception(e)
   File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
     reraise(exc_type, exc_value, tb)
   File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
     raise value
   File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
     rv = self.dispatch_request()
   File "/var/www/abc/abc/venv3/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
     return self.view_functions[rule.endpoint](**req.view_args)
   File "/var/www/abc/abc/main.py", line 133, in refresh
     updateDir()
   File "/var/www/abc/abc/main.py", line 77, in updateDir
     os.makedirs(finalPath, exist_ok=True)
   File "/usr/local/lib/python3.6/os.py", line 210, in makedirs
     makedirs(head, mode, exist_ok)
   File "/usr/local/lib/python3.6/os.py", line 210, in makedirs
     makedirs(head, mode, exist_ok)
   File "/usr/local/lib/python3.6/os.py", line 210, in makedirs
     makedirs(head, mode, exist_ok)
   File "/usr/local/lib/python3.6/os.py", line 220, in makedirs
     mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 'static'

I've already given www-data permissions to write to the 'static' folder and it still shows the error.

Feel free to ask questions if I haven't covered everything in order to help me.

Davkk
  • 23
  • 1
  • 5
  • This seems to be closely related to https://stackoverflow.com/questions/18963494/django-file-upload-errno-13-permission-denied-static – cardiff space man Mar 30 '18 at 19:19
  • I've seen this post and the instructions there didn't work for me. I'm using flask not django. – Davkk Mar 30 '18 at 19:30
  • I recommend preemptively linking to material like that in your questions in the future. And then in a case like this one, the django tool is different from the flask tool, but there are common elements, particularly it would appear, Apache server. So hypothetically you would have linked to the other answer and briefly discussed its bigger lessons, like checking ownership, and checking the mapping of URLs to physical paths on the server. This information would help other web developers who might have experience with your issue. – cardiff space man Mar 30 '18 at 20:09

1 Answers1

0

Don't use a relative path name. The current working directory of the process will not usually be where your code is. You need to calculate an absolute path relative to some anchor point. See:

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134