0

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

  1. Try change IIS config, enviroment etc - No Dice
  2. Change code - We are noobs, idk what's wrong but clearly doesn't work
  3. Google it - too sparse for info
  4. 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

Havoc
  • 1
  • 1
  • Many Python module authors do not put Windows into consideration, so such can be expected. That's why starting from Azure App Service Microsoft recommends you use Linux for Python web apps, https://learn.microsoft.com/en-us/visualstudio/python/managing-python-on-azure-app-service?view=vs-2019 You should migrate such apps to a Linux machine, even when you run on premise. – Lex Li Oct 26 '20 at 19:35
  • I see... that sucks since our requirement is strict and this really hinders our development. thanks for the information – Havoc Oct 27 '20 at 03:43
  • After iis8 (including iis8), Excel is supported on iis, and are you using COM componenet to run the excel? If so, then it will work on CMD, but not on iis. If you use openxml, then it can work in iis, but there may not be suitable components in php. – samwu Oct 27 '20 at 07:06
  • I see, I didn't know about this info. Idk if it is using COM component or not but there's pythoncom that I copy from another post/tuorial that use it for xlwings. I test it out this theory on the server. Thanks for this tip. – Havoc Oct 27 '20 at 09:35

0 Answers0