skip to Main Content

I just make a python application and it is working fine on my localhost but on the server it runs the simple route (‘/’) but with the name (‘/hello’) it is not working,
My hosting is shared Cpanel lined server
The Error I got from the logs is

The application process exited prematurely.

Here is my Code

from flask import Flask, render_template, request, jsonify
import bs4 as bs
import os
import requests
import json

from flask_cors import CORS, cross_origin
project_root = os.path.dirname(os.path.realpath('_file_'))
template_path = os.path.join(project_root, 'templates')
static_path = os.path.join(project_root, 'static')

app = Flask(_name_, template_folder=template_path, static_folder=static_path)
app.config['DEBUG'] = True


@app.route("/hello")

def index():
    try:
      return "hello"
    except Exception as e:
            print(str(e))
            return e

if _name_ == "_main_":
   app.run(debug=True, 
         host='0.0.0.0', 
         port=9000, 
         threaded=True)

2

Answers


  1. It would be helpful to see an example of the code that works with /. I suspect that the issue is not changing / to /hello, but rather something else.

    The error message “The application process exited prematurely.” sounds like there is probably a syntax error in your code. Instead of running it via cPanel, have you tried executing it from the command line?

    After installing your dependencies and trying to run your code, I get this error:

    -> % python foo.py         
    Traceback (most recent call last):
      File "foo.py", line 12, in <module>
        app = Flask(_name_, template_folder=template_path, static_folder=static_path)
    NameError: name '_name_' is not defined
    

    After correcting all instances of _name_ to __name__ and _main_ to __main__ your code runs and I can access the endpoint /hello. You can read more about '__main__' in the Python docs: https://docs.python.org/3/library/main.html

    Login or Signup to reply.
  2. After editing the .htaccess and putting this line of code in it

    RewriteEngine On 
      RewriteBase /
    

    and it works!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search