[PYTHON] Permission error when reading Django upload files

What you want to solve

-When I try to read the file uploaded by Django and use cron to perform some operation, a permission error occurs if the file cannot be read. -The authority when uploading a file is "600"

What I tried

As a prerequisite, it is an environment that requires administrator privileges when performing chmod.

os.py


import os
os.system('sudo shmod 644 path')

python os.py-> Switch permissions. Run with cron-> without switching permissions.

subprocess.py


import subprocess
subprocess.call('sudo shmod 644 path')

python subprocess.py-> Switch permissions. Run with cron-> without switching permissions.

solution

By writing "FILE_UPLOAD_PERMISSIONS = 0o644" in settings.py, the permission of the uploaded file became "644". It seems that the default is "600" in consideration of security, but it took time. ..

I don't know why it didn't switch in subprocess or os.system when I cron it.

Recommended Posts

Permission error when reading Django upload files
Upload files with Django
Memorandum (Countermeasures against Unicode Decode Error when reading CSV files)
[Django] Error encountered when deploying heroku Part 2
[Django] Error when SlugField is specified in .filter ()
Display error message when login fails in Django
Case sensitive when reading and writing INI files
How to upload files in Django generic class view
Django2.2 SQLite3 version error
File upload with django
[Python] Reading CSV files
How to handle static files when deploying to production with Django
CSRF validation error when accessing django 3.0 admin page in Chrome
[Python: UnicodeDecodeError] One of the error solutions when reading CSV
When I put Django in my home directory, I was addicted to static files with permission errors