This is my first time putting a question here. Some background, I started coding on Django this year and Python more than a year but less than 2 years so I don't much. This problem is a concern to my what I developing in at work. And my team working on it is novice or no experience on coding Python or Django or both.
The Problem
We have a web app based on Django 3.0.2 and use MSSQL for the db. Our company policy is to use Windows server and IIS as the prod and test server. We done a lot of work on it and all work well except for some python library and Django module that don't work, mainly Xlwings and Django-post-office. For XLwings, it doesn't run the code and Excel(we have valid license and latest Excel programme on the server).
code below;
filepath = BASE_DIR + '\\media\\Template.xlsm'
temp_path = BASE_DIR + '\\media\\' + '{}.{}'.format(uuid4().hex, 'xlsm')
shutil.copyfile(filepath, temp_path)
pythoncom.CoInitialize()
app1 = xw.App(visible=True)
wt = xw.Book(temp_path)
sht = wt.sheets['Cover']
sht.range('E5').value = request.POST.get('year')
sht.range('E6').value = request.POST.get('company')
sht.range('E7').value = companydata.employer_no
sht.range('E8').value = email
wt.save(temp_path)
app1.quit()
As for Django-post-office, we have a module using it that got it working but other modules using it doesn't work. Same code that is used except for the template and subject.
Code below;
plaintext = get_template('template.txt')
htmly = get_template('template.html')
mail.send(
[email],
NAME_EMAIL_DOMAIN,
message = plaintext.render(info),
html_message = htmly.render(info),
subject = f'Subject',
priority = 'now',
attachments = {
'RemunerationTemplate.xlsm': temp_path,
},
)
The bizarre thing is it work on CMD but it just doesn't work on IIS. We don't know why and how to rectify it. We ask the IT Support (department responsible for the servers) said that the test server is not restricted.
The Fail Fix
- Try change IIS config, enviroment etc - No Dice
- Change code - We are noobs, idk what's wrong but clearly doesn't work
- Google it - too sparse for info
- Ask the IT support guy if he has any idea - he doesn't care much on it and just say to me to piss off
So, I grateful if any help for this since we are nearing the deployment date and this issue is haunting me in my sleep for the past week already. Thank You