【问题标题】:WARNING: Do not use the development server in a production environment and the requested URL was not found on the server警告:不要在生产环境中使用开发服务器,并且在服务器上找不到请求的 URL
【发布时间】:2021-06-08 09:04:31
【问题描述】:

使用 hello.py 它正在运行“Hello word”。 但是当我运行应用程序 (webhook_weather.py) 时它不起作用,我收到以下错误: 我有

set FLASK_ENV=development
FLASK_APP= webhook_weather.py
flask run

(helloworld-x2biACXm) C:\Users\Jayanth\Desktop\helloworld>python webhook_weather.py
Starting app on port 80
• Serving Flask app 'webhook_weather' (lazy loading)
• Environment: development
• Debug mode: on
• Restarting with stat
Starting app on port 80
• Debugger is active!
• Debugger PIN: 119-286-619
• Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
• Running on http://192.168.43.87:80/ (Press CTRL+C to quit)

192.168.43.87 - - [04/Jun/2021 14:38:39] "GET / HTTP/1.1" 404 -

我无法打开应用页面。我会得到如下所示的页面:

未找到
在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。

当我运行 python 文件时,我得到了 AttributeError:

AttributeError: 'NoneType' 对象没有属性 'get'

Traceback(最近一次调用最后一次) 文件“C:\Users\Jayanth.virtualenvs\helloworld-CPu4KsHf\lib\site-packages\flask\app.py”,第 2088 行,调用中 return self.wsgi_app(environ, start_response) wsgi_app 中的文件“C:\Users\Jayanth.virtualenvs\helloworld-CPu4KsHf\lib\site-packages\flask\app.py”,第 2073 行 响应 = self.handle_exception(e) wsgi_app 中的文件“C:\Users\Jayanth.virtualenvs\helloworld-CPu4KsHf\lib\site-packages\flask\app.py”,第 2070 行 响应 = self.full_dispatch_request() 文件“C:\Users\Jayanth.virtualenvs\helloworld-CPu4KsHf\lib\site-packages\flask\app.py”,第 1515 行,在 full_dispatch_request rv = self.handle_user_exception(e) 文件“C:\Users\Jayanth.virtualenvs\helloworld-CPu4KsHf\lib\site-packages\flask\app.py”,第 1513 行,在 full_dispatch_request rv = self.dispatch_request() 文件“C:\Users\Jayanth.virtualenvs\helloworld-CPu4KsHf\lib\site-packages\flask\app.py”,第 1499 行,在 dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) Webhook 中的文件“D:\ExcelSoft\venil\Cognitive-Behavioural-Chatbot-master\helloworld\web.py”,第 26 行 res = processRequest(req) 文件“D:\ExcelSoft\venil\Cognitive-Behavioural-Chatbot-master\helloworld\web.py”,第 36 行,在 processRequest print ("开始 processRequest...",req.get("result").get("action")) AttributeError: 'NoneType' 对象没有属性 'get'

我尝试过:http://localhost/webhook

【问题讨论】:

  • 您还需要在webhook_weather.py 中显示代码。如果它没有/ 的路由,你会得到一个 404。
  • 另外,您在第一个环境变量中有错字。这是FLASK_ENV,而不是FASK_ENV。
  • 是的,它是 FLASK_ENV ,拼写错误..
  • 这些是应用路由,@app.route('/webhook', methods=['POST']) ; @app.route('/test', methods=['GET']) ;和 @app.route('/static_reply', methods=['POST']) 。
  • 您之前链接的存储库中没有helloworld/web.py。

标签: python


【解决方案1】:

这些是应用路由,
@app.route('/webhook', methods=['POST'])
@app.route('/test', methods=['GET']
@app.route('/static_reply', methods=['POST'])

使用这些路由,尝试导航到 http://localhost/ 确实会返回 404;没有任何东西被路由到/。

改用 http://localhost/test...

【讨论】:

  • 有了这个localhost/test,我得到的输出是“你好,我的朋友!!”
  • 这可能就是/test 路由的作用。这不符合您的预期吗?
  • 我试过 localhost/test ,我得到的输出是“你好,我的朋友!!”这部分工作正常,但如果我使用 192.168.43.87:80 我得到 404。如何使用完整程序(应用程序)? @app.route('/webhook', methods=['POST']) ; @app.route('/static_reply', methods=['POST']) 。这是与聊天机器人相关的链接:github.com/avirupm97/Cognitive-Behavioural-Chatbot
  • 您特别想做什么?您链接的 repo 中的 webhook_weather.py 文件只有一些代码来获取位置的天气作为 webhook 响应,没有 PDF 中概述的检测或聊天机器人内容。
  • /test 路由正常,但是 /webhook 和 /static_reply 呢?
猜你喜欢
  • 1970-01-01
  • 2018-12-04
  • 2017-06-22
  • 2022-06-27
  • 2014-03-05
  • 2017-03-21
  • 2010-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多