【发布时间】:2018-03-31 19:50:05
【问题描述】:
当我在浏览器中打开链接 0.0.0.0:5000 时,我总是在浏览器上收到消息“无法访问此站点” 代码似乎在工作,因为我在控制台上收到了这条消息
在http://0.0.0.0:5000/ 上运行(按 CTRL+C 退出)
这是我正在使用的代码
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 实际连接到您机器上运行的服务器。
-
我实际上试过了,它不工作,它在使用 0.0.0.0:5000 之前工作但现在我不知道是什么问题
-
@kindall 我找到了解决方案,您的评论确实有帮助,我将主机更改为 127.0.0.1 但我忘记了烧瓶在模板文件夹中查找 index.html 文件而我没有放在那里
标签: python google-chrome flask