我正在尝试在AWS Elastic beantalk上部署我的flask应用程序。托管的Web应用程序的链接为here。但是,只有在我的本地服务器打开时,它才起作用。它在控制台中显示的警告为Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5000/hi. (Reason: CORS request did not succeed).
application = app = Flask(__name__)
CORS(app)
@app.route("/")
def showHome():
return render_template('index.html')
@app.route("/<msg>")
def helloWorld(msg):
print(msg)
CLIENT_ACCESS_TOKEN = "*********************"
ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN)
req = ai.text_request()
req.lang = 'de'
req.session_id = "<SESSION ID, UNIQUE FOR EACH USER>"
req.query = msg
response = req.getresponse()
reader = codecs.getreader("utf-8")
answerJSON = json.load(reader(response))
answer = answerJSON['result']['fulfillment']['speech']
if str.lower(str(answer)).find('registered')!=-1:
return (answer+button)
if answer == "I haven't got your query. Please, make sure you have clearly stated your problem/query?":
return (answer+button)
return (answer)
if __name__=='__main__':
app.run(host="0.0.0.0")
帮助我解决问题。