Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

flask - Every time I update my CPanel Python web app I get an Error Message. How can I fix this?

Everytime I update my CPanel, Python web app I get an error though the error is continually changing.

Errors:

1."Not Found The requested URL was not found on the server. 
   If you entered the URL manually please check your spelling and try again."
2. 500
3. Other random errors

I have all my pip installs in order. I am running a requirements.txt. I am able to run the boilerplate code successfully. Even if I just change the message to output without changing any file paths I get an error.

I can upload the same code when I originally create the program, but when I change it and run it again it doesn't work. So it appears it's not even the code, it's a problem recognizing the update.

Any suggestions? Or better methods of doing this without Heroku?

Boilerplate code:

app.py:

import os
import sys


sys.path.insert(0, os.path.dirname(__file__))


def app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    message = 'It works!
'
    version = 'Python v' + sys.version.split()[0] + '
'
    response = '
'.join([message, version])
    return [response.encode()]

passenger_wsgi.py:

import imp
import os
import sys


sys.path.insert(0, os.path.dirname(__file__))

wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.app

Web app configuration:

Python version: 3.7.8
Application root: maindir/test.com/py
Application URL: test.com/py
Application startup file: app.py
Application entry point: app
Passenger log file: /home/userdir/maindir/test.com/logs/passengar.log 

What I want to do is something like this:

app.py:

import os
from flask import Flask
from flask import *
    if os.path.exists("data.py"):
        import data

app = Flask(__name__)

@app.route("/py")
def main_():
    return "flask works"

//something like this, but using Jinja to update
//the html doc with data from data.py
@app.route("/data")
def data():
    return render_template("data.html")
 
if __name__ == "__main__": app.run(); 

data.py:

import matplotlib.pyplot as plt
import numpy as np
x = np.loadtxt('tempcdata.txt', unpack=True)
plt.grid(True)
plt.plot(x)

plt.xlabel('Time')
plt.ylabel('Temperature C')
plt.title('Temperature Data
')
plt.show()
question from:https://stackoverflow.com/questions/65877380/every-time-i-update-my-cpanel-python-web-app-i-get-an-error-message-how-can-i-f

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...