-2

Code is running fine with local system but I'm getting the following error whenever I try to submit data to my Flask form:

Error: Method Not Allowed The method is not allowed for the requested URL.

Relevant parts of my code are as follows:

pytesseract.pytesseract.tesseract_cmd = 'C:\\Users\\Abhi\\AppData\\Local\\Programs\\Python\\Python37-32\\Lib\\site-packages\\pytesseract\\Tesseract-OCR\\tesseract.exe'
#Poppler executable file is mandatory to load
PDFTOPPMPATH = r"C:\Users\Abhi\Downloads\poppler-0.68.0_x86\poppler-0.68.0\bin\pdftoppm.exe"
PDFFILE = "C:\\Users\\Abhi\\rep.pdf"
subprocess.Popen('"%s" -png "%s" out' % (PDFTOPPMPATH, PDFFILE))

app = Flask(__name__)

@app.route('/', methods=['POST'])
def predict():

    im = Image.open("out-2.png")
    rgb_im = im.convert('RGB')
    rgb_im.save('m.jpg')

    im = Image.open("m.jpg")
    text1 = pytesseract.image_to_string(im, lang = 'eng')

    with open("report.txt","w") as f:
        f.write(text1)


    para = ["Emissivity","Refl. temp.","Distance","Relative humidity","Atmospheric temperature","Transmission"]

    f=open('report.txt')
    lines=f.readlines()

    #lines.remove("\n")
    for i in range(0,len(lines)):
        if "jpg" in lines[i]:
            end1 = i-1
        if "MEASUREMENTS (°C)" in lines[i]:
            start1 = i+1
        if "Report" in lines[i]:
            end2 = i-1
        if "Transmission" in lines[i]:
            trans = i+1
        #print(str(start1) + " " + str(end1)+" " +str(trans) + " " + str(end2))

    for i in range(start1-1,trans):
        return str(lines[i])

if __name__ == '__main__':
    #p = int(os.getenv('PORT', 5000))
    #app.run(debug = True, port=p, host='0.0.0.0')
    #app.run()
    app.run(debug=True, use_reloader=False)
  • 4
    Does this answer your question? [Method Not Allowed flask error 405](https://stackoverflow.com/questions/21689364/method-not-allowed-flask-error-405) – snwflk Dec 27 '19 at 21:45

1 Answers1

0

What is happening here is that route does not accept any url methods.its look like you are trying to return a string.U have to convert that in to a json.use Mashmellow to serialize ur output.or use bellow method(using json lib to covert list to a json format)

import json

def index():
    lines=[1,2,3,4,5]

    return json.dumps(lines[0])

use above template and customize it to your needs.hope this help

nik huge
  • 109
  • 9