I have a web application that, among other things, will query a database and create an Excel spreadsheet with the data. I need to save the spreadsheet to the server's disk before sending the file to the client machine. I'm using the Flask framework and openpyxl to generate the spreadsheet. Everything works fine when running on Flask's dev server, but the real server is Apache2 with WSGI. When I run it there, a "Permission Denied" error is raised when it tries to save the spreadsheet. I don't know what Python's working directory is when running in Apache/WSGI.
Is there a way, maybe in the WSGI config file, to change the working directory, or somehow control where it will save to? If possible, I'd like to use relative paths for saving (it makes the code more portable) which is why changing the working directory is the best solution.
The server executes the web app and sends related information and a callback function to the app. The request is processed on the app side, and a response is sent back to the server utilizing the callback function. Sometimes there might be one or more WSGI middlewares between the server and the web app.
mod_wsgi is an Apache module which can host any Python WSGI application, including Django. Django will work with any version of Apache which supports mod_wsgi. The official mod_wsgi documentation is your source for all the details about how to use mod_wsgi.
The WSGI represents for web server gateway interface. It's a standard designed by the Python community to make the web development in Python easier. It builds a bridge between a Python web app and a server software.
The Web Server Gateway Interface (WSGI) is a standard interface between web server software and web applications written in Python.
I had a similar problem where I wanted to use a glob() with a relative path. It worked in my development environment but not on the server with mod_wsgi. I discovered here that there is a 'home=' option that you can add to the WSGIDaemonProcess directive to set the initial working directory of your application. You find that in the virtual host file (on my system in /etc/apache2/sites-available/mysite.conf)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With