Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Showing Internal Server Error in flask python


from prettytable import PrettyTable
from flask import Flask, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
class Structure_Cal:
    def __init__(self, Slope, Texture,Soil_depth,Catchment_area,Land_use):
        self.slope=Slope
        self.texture=Texture
        self.soil_depth=Soil_depth
        self.catchment_area=Catchment_area
        self.land_use=Land_use
    def sturcture_defined(self, index):
        stucture_def=['Field bunding with waste weir','Outlet structure (grassed turfing or stone pitching)',
                      'Masonry mini drop (outlet)','On Farm lined pond (small)','On Farm unlined pond (small)',
                      'Farm pond (big) IFS' ,'Staggered trench','Field boundary trench-cum-bund','Staggered trench',
                      'Diversion drain with WHS','contour stone bunding','recharge pit','contour stone bunding',
                      'Vegetative and live check dams','loose boulder check dams','earthern check dams with surplus weir',
                      'Gabion structure','Percolation tanks with dug well ','Stream bank protection measures','WHS',
                      'MasonryCheck dam/drop inlet structure','Stream bank protection measures' ]
        return stucture_def[index]
    def strcuture_calculation(self):
        """ This is the function that 
        calcualte the Strcture with the value
        of slope, soil_depth, catchment_area,
        land_use user values
        """
        ### For the first one ####
        if (int(self.slope) in range(3, 6) and self.texture=='Any soil' 
               and int(self.soil_depth) in range(50,101) and self.catchment_area ==0 and self.land_use=='Arable Upland'):
            idf=0
            fin_struct=self.sturcture_defined(idf)
        elif (int(self.slope) in range(1, 4) and self.texture=='Any soil' 
               and int(self.soil_depth) in range(1,101) and self.catchment_area ==1 and self.land_use=='Arable Medium land'):
            idf=1
            fin_struct=self.sturcture_defined(idf)
        return fin_struct
###### Testing ###########
if __name__ == '__main__':
    

    
    if request.method == "POST":
        Slope = request.form["ENTER THE VALUE"]
    Texture=input('Enter Texture Value:')
    Soil_depth=int(input('Enter Slope-Depth Value:'))
    Catchment_area=int(input('Enter Catchment-area Value:'))
    Land_use=input('Enter Land-use Value:')
    ########
    Struture=Structure_Cal(Slope,Texture,Soil_depth,Catchment_area,Land_use)
    F_Structure=Struture.strcuture_calculation()
    ########  Output #########
    data_output=PrettyTable(['Slope','Texture','Soil_depth','Catchment_area','Land_use','Structure_Output'])
    data_output.add_row([Slope,Texture,Soil_depth,Catchment_area,Land_use,F_Structure])
    ### Output to Excel
    with open('structure_output_final.csv', 'w', newline='') as f_output:
        f_output.write(data_output.get_csv_string())
    
    app.run()
    ####
    print(data_output)


What I have tried:

Showing Internal Server Error in flask python
Posted
Updated 1-Feb-23 19:08pm
Comments
Richard MacCutchan 2-Feb-23 3:23am    
You need to use the debugger to find out where the error occurs.
Dave Kreskowiak 2-Feb-23 8:51am    
The 500 - Internal Server Error just means there was some kind of problem in the server-side code that caused a crash, or exception. You have to run that code under a debugger, or pepper the code with output statements that show you the values of variables to figure out where the problem is and why the variables are not getting the values you expect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900