When changing/updating infromation in the Admin backend of Django app, I'm met with a permission error.
A couple of things to note: -It only happens when I try to upload a document, or change an entry with a document in it. -Adding/editing database entries with no files attached to them is fine! -On my local version, everything works fine.
The next logical step for me is to check file/folder permissions, so I changed everything to on my testing server 'lrwxrwxrwx', including the uploads folder, the entirty of Python3.5 (I changed back after that did not solve it, I know it's pretty risky to leave it at all permissions).
[Errno 13] Permission denied
Request Method: POST
Request URL: https://admin/inhouse/document/1704/change/
Django Version: 1.11
Exception Type: PermissionError
Exception Value:
[Errno 13] Permission denied
Exception Location: /usr/lib/python3.5/subprocess.py in _execute_child, line 1551
Python Executable: /home/ubuntu/.virtualenv/bin/python
Python Version: 3.5.2
Python Path:
['/home/ubuntu/.virtualenv/lib/python35.zip',
'/home/ubuntu/.virtualenv/lib/python3.5',
'/home/ubuntu/.virtualenv/lib/python3.5/plat-x86_64-linux-gnu',
'/home/ubuntu/.virtualenv/lib/python3.5/lib-dynload',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/home/ubuntu/.virtualenv/lib/python3.5/site-packages',
'/home/ubuntu/foodlegal/foodlegal-repo',
'/home/ubuntu/foodlegal',
'/home/ubuntu/.virtualenv/lib/python3.5/site-packages/IPython/extensions']
And this is the function that is causing this entire issue
@receiver(post_save, sender=Document)
def convert_pdf_upload(sender, instance, **kwargs):
if not instance.document_file:
return
current_path = settings.BASE_DIR+'/foodlegal/'+instance.document_file.url
pdf_path = settings.BASE_DIR+'/foodlegal/uploads/documents/'+str(instance.id)+'.pdf'
swf_path = settings.BASE_DIR+'/foodlegal/uploads/documents/'+str(instance.id)+'.swf'
txt_path = settings.BASE_DIR+'/foodlegal/uploads/documents/'+str(instance.id)+'.txt'
pdf2swf_path = settings.BASE_DIR+'/foodlegal/tools/pdf2swf'
pdftotext_path = settings.BASE_DIR+'/foodlegal/tools/pdftotext'
try:
os.rename(current_path, pdf_path)
except OSError:
pass
subprocess.call([pdf2swf_path, pdf_path, '-o', swf_path, '-f', '-T', '9', '-t', '-s',
'storeallcharacters'])
subprocess.call([pdftotext_path, pdf_path])
txt = codecs.open(txt_path, "r", encoding='utf-8', errors='ignore')
file_txt = txt.read()
instance.file_text = re.sub('[^A-Za-z0-9 ]+', ' ', file_txt)
if instance.content_type in [1, 2]:
instance.file_text = re.sub('[^A-Za-z0-9 ]+', ' ', instance.document_content)
post_save.disconnect(convert_pdf_upload, sender=Document)
instance.save()
post_save.connect(convert_pdf_upload, sender=Document)
Server version: Apache/2.4.18 (Ubuntu) Distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenial
Tried changing permisions via chmod 777 to folders including Python3.5, entirety of InHouse Django App, and uploads folder, and was unsuccessful.
It could very well be a permission chmod fix type of thing, but what folder did I miss?