Reputation: 563
I am getting a 503 error trying to test the initial install of a Python 3.6 project on my host which uses cPanel. I am not adding anything yet, literally just hitting the URL. Here is the boilerplate passenger_wsgi.py file created when adding the app via cPanel:
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
message = 'It works!\n'
version = 'Python %s\n' % sys.version.split()[0]
response = '\n'.join([message, version])
return [response.encode()]
The public URL can be found here: https://slickmcfavorite.com/36
I can deploy a Python 2.7 project and get the "It works!" no problem.
This is my first attempt at a Python app on cPanel, so I don't know if there are extra settings needed for 3.6 vs 2.7. Unfortunately, my host says they're an "Unmanaged Host" so they won't help me.
Any advice from troubleshooting to how to approach my host's support team would be appreciated. Even as an unmanaged host, seems strange that using "their" provided software to install an app doesn't work and they won't support it.
Again a noob, so any advice is welcome. Thanks in advance.
Upvotes: 0
Views: 1956
Reputation: 11
I add it as info for any other that comes in this thread. Assuming your system is Litespeed + Cloudlinux, it's very, very possible that it's due to a bug in the Litespeed webserver and missing some cloudlinux modules. So, the details are:
Python Web Application shows 503 error with the following records in the logs:
"Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings' "
"Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'django' "
Note: Only python3 applications using virtualenv (v.20.13.0) on LiteSpeed Web Server are affected.
/usr/local/lsws/admin/misc/lsup.sh -d -f -v 6.0.11
The currently installed build number can also be checked with the following command:
cat /usr/local/lsws/BUILD
This should solve the issue with Python Applications with Python version 2.7 to 3.9, but not for Python 3.10 because LiteSpeed doesn't support Python 3.10 for now
Here would be the detailed report and solution (just as external reference):
hope it helps someone!
Upvotes: 1
Reputation: 2539
Assuming that your cPanel instance is on Linux then you need to add
#!/path/to/your/python
At the top of your script.
Upvotes: 0