如何解决python中的404烧瓶错误?

如何解决python中的404烧瓶错误?,python,flask,Python,Flask,我正在处理文本文件和学习使用Flask构建API的新知识,我想从文本文件中提取数据,并希望生成JSON输出,但不幸的是,当我加载API URL时,我一直得到这个404页面,有人能帮我吗 提前谢谢 下面是代码 重新导入 从烧瓶进口烧瓶 从烧瓶进口请求 导入json app=烧瓶(名称) @app.route('/flask_resume',methods=[“POST”]) def flasku resume(): file=request.files['file'] files=file.rea

我正在处理文本文件和学习使用Flask构建API的新知识,我想从文本文件中提取数据,并希望生成JSON输出,但不幸的是,当我加载API URL时,我一直得到这个404页面,有人能帮我吗 提前谢谢

下面是代码

重新导入
从烧瓶进口烧瓶
从烧瓶进口请求
导入json
app=烧瓶(名称)
@app.route('/flask_resume',methods=[“POST”])
def flasku resume():
file=request.files['file']
files=file.read()
返回文件
#提取工作经验和摘要标题
打开(文件,'r',编码='latin-1')作为文件1:
打开('Details.txt','r',encoding='latin-1')作为文件2:
相同=设置(文件1)。交叉点(文件2)
相同。放弃(“\n”)
单词列表=[]
对于同一行:
单词列表。追加(行)
单词列表=列表(映射(str.strip,单词列表))
打印('单词列表',单词列表)
#提取其他标题
打开(文件,'r',编码='latin-1')作为文件3:
打开('other_details.txt','r',encoding='latin-1')作为文件4:
same1=集合(文件3).交叉点(文件4)
same1.discard(“\n”)
单词_extract=[]
对于same1中的f:
单词\u摘录.附加(f)
单词提取=列表(映射(str.strip,单词提取))
打印('words\u extract',words\u extract)
#替换提取的标题的函数
def multiwordReplace(文本,文字):
rc=re.compile('|'.join(map(re.escape,wordDic)))
def翻译(匹配):
return wordDic[match.group(0)]
返回rc.sub(翻译,文本)
str1=open(文件,'r',encoding='latin-1')
str1=str1.read()
wordDic1=dict((k,'Summary'),表示单词列表中的k)
wordDic2=dict((k,'xyz'),表示单词中的k\u摘录)
wordDic=dict(wordDic1,**wordDic2)
打印(wordDic)
以open('set.txt','w',encoding='latin-1')作为填充:
str2=多字替换(str1,字DIC)
填充写入(str2)
#提取摘要段落
将open(“set.txt”,encoding='latin-1')作为填充,将open(“fgl.txt”,“w',encoding='latin-1')作为输出文件:
复制=错误
对于word in words\u摘录:
对于填充中的线:
如果line.strip()=“摘要”:
复制=真
elif line.strip()=“xyz”:
复制=错误
elif副本:
输出文件。写入(行)
如果名称=“\uuuuu main\uuuuuuuu”:
app.run(debug=True)
并且输出屏幕是


您需要在URL-
如果uuu name uuu==“uuuu main”:

@app.route(“/”)
def hello():
返回“你好”

如果您希望
flask\u resume
成为您的登录页,那么它应该是
'/'
,而不是没有任何方法的
'/flask\u resume'

完整代码-

import re
from flask import Flask
from flask import request
import json

app= Flask(__name__)

@app.route('/flask_resume',methods =["POST"])
def flask_resume():
    file = request.files['file']

    files = file.read()
    return files

    #extracting workexperience and summary titles
    with open(files,'r', encoding='latin-1')as file1:
        with open('Details.txt','r',encoding='latin-1' )as file2:
            same = set(file1).intersection(file2)

    same.discard('\n')
    words_list = []

    for line in same:
        words_list.append(line)

    words_list = list(map(str.strip,words_list))
    print ('words_list', words_list)

    #extracting other titles
    with open(files,'r', encoding='latin-1')as file3:
        with open('other_details.txt','r',encoding='latin-1' )as file4:
            same1 = set(file3).intersection(file4)

    same1.discard('\n')
    words_extract = []

    for f in same1:
        words_extract.append(f)

    words_extract = list(map(str.strip,words_extract))
    print ('words_extract', words_extract)

    #function to replace extracted titles        
    def multiwordReplace(text, wordDic):
        rc = re.compile('|'.join(map(re.escape, wordDic)))
        def translate(match):
            return wordDic[match.group(0)]
        return rc.sub(translate, text)


    str1 = open(files,'r', encoding='latin-1')
    str1 = str1.read()

    wordDic1 = dict((k,'Summary') for k in words_list)
    wordDic2 = dict((k,'xyz') for k in words_extract)
    wordDic = dict(wordDic1, **wordDic2)
    print(wordDic)

    with open ('set.txt','w', encoding='latin-1') as infile:
        str2 = multiwordReplace(str1,wordDic)
        infile.write(str2)

    #extracting summary paragraphs
    with open("set.txt", encoding='latin-1')as infile,open("fgl.txt",'w', encoding='latin-1')as outfile:
        copy = False
        for word in words_extract:
            for line in infile:
                if line.strip() == "Summary":
                    copy = True

                elif line.strip() == "xyz":
                    copy = False
                elif copy:
                    outfile.write(line)

@app.route('/')
def hello():
    return "hello"

if __name__ == "__main__": 
    app.run(debug=True)```

你知道HTTP方法(get、post等)吗?你的API只对POST方法开放,但你对GET的调用是开放的。@Taegyung我对python和Flask不太熟悉,你能详细解释一下吗,问题是我想在完成执行后将输出发布到其他因素上werkzeug.exceptions.BadRequestKeyError werkzeug.exceptions.BadRequestKeyError:400错误请求:浏览器(或代理)发送了此服务器无法理解的请求。KeyError:“files”这是我完成此操作后的输出@Khilesh chauhan是否可以粘贴代码的屏幕截图和您的输出?