当我在浏览器中打开链接0.0.0.0:5000时,我总是在浏览器上看到“此站点无法到达”消息 代码似乎是工作,因为我得到的控制台This site can not be reached [flask,python]
运行在http://0.0.0.0:5000/对此消息(按Ctrl + C退出)
这里是我使用
0123码from flask import Flask, render_template, request
from scipy.misc import imsave, imread, imresize
import numpy as np
import keras.models
import re
import sys
import os
from load import *
sys.path.append(os.path.abspath('./model'))
app = Flask(__name__)
global model, graph
model, graph = init()
def convertImage(imData):
imgstr = re.search(r'base64(.*'.imData).group(1)
with open('output.png', 'wb') as output:
output.write(imgstr.decode('base64'))
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict', methods=['GET', 'POST'])
def predict():
imData = request.get_data()
convertImage(imData)
x = imread('output.png', mode = 'L')
x = np.invert(x)
x = imresize(x, 48, 48)
x = x.reshape(1,48,48,1)
with graph.as_default():
out = model.predict(x)
response = np.array_str(np.argmax(out))
return response
if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
0.0.0.0不是一个有效的IP地址,所以你实际上不能连接到它。当服务器说它是“在0.0.0.0上运行”时,这意味着它正在接受任何网络适配器上的连接,而不是特定的连接。使用127.0.0.1实际连接到机器上运行的服务器。 – kindall
我试过,实际上,它不工作,它使用0.0.0.0:5000之前工作,但现在我不知道什么是问题 – Oussama
@kindall我发现解决方案和您的意见真的帮助,我将主机更改为127.0.0.1,但我忘了烧瓶在模板文件夹中查找index.html文件,我没有放在那里 – Oussama