1

我正在使用 Flask-Ask 开发 Alexa Skill。当我测试我的技能时,会抛出错误。

我为 Flask-Ask 使用 nginx 代理。

(以前,它在另一台服务器上运行良好。)现在,另一台服务器也有同样的问题。所以我认为还有另一个问题,不是代码。我还看到了Flask Message Flashing 错误 - flask.debughelpers.FormDataRoutingRedirect,但它没有解决。

代码:

from flask import Flask
from flask_ask import Ask, statement

app = Flask(__name__)
ask = Ask(app, '/')

@ask.launch
def launch():
    speech_text = "Hello!"
    return statement(speech_text).simple_card('Hello', speech_text)

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

控制台输出:

127.0.0.1 - - [15/May/2019 10:41:03] "POST  HTTP/1.0" 500 -
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/.local/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/.local/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1590, in dispatch_request
    self.raise_routing_exception(req)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1576, in raise_routing_exception
    raise FormDataRoutingRedirect(request)
flask.debughelpers.FormDataRoutingRedirect: b'A request was sent to this URL (http://127.0.0.1:5000/) but a redirect was issued automatically by the routing system to "http://127.0.0.1:5000/".  Make sure to directly send your POST-request to this URL since we can't make browsers or HTTP clients redirect with form data reliably or without user interaction.  Note: this exception is only raised in debug mode'
127.0.0.1 - - [15/May/2019 10:41:05] "POST  HTTP/1.0" 500 -
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/.local/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/user/.local/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1590, in dispatch_request
    self.raise_routing_exception(req)
  File "/home/user/.local/lib/python3.7/site-packages/flask/app.py", line 1576, in raise_routing_exception
    raise FormDataRoutingRedirect(request)
flask.debughelpers.FormDataRoutingRedirect: b'A request was sent to this URL (http://127.0.0.1:5000/) but a redirect was issued automatically by the routing system to "http://127.0.0.1:5000/".  Make sure to directly send your POST-request to this URL since we can't make browsers or HTTP clients redirect with form data reliably or without user interaction.  Note: this exception is only raised in debug mode'

nginx配置:

server {
    listen       80;
    server_name  mydomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen       443 ssl;
    server_name  mydomain.com;

    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

    location / {
        deny  all;
    }

    location /alexa {
        proxy_pass http://127.0.0.1:5000/;
    }
}

我的环境:

  • Ubuntu 19.04
  • Python 3.7.3
  • nginx/1.15.12
4

1 回答 1

1

为了解决这个问题...

1.编辑nginx配置

/从中删除尾随proxy_pass

proxy_pass http://127.0.0.1:5000/;
proxy_pass http://127.0.0.1:5000;

2.编辑python代码

它需要与 nginx 配置匹配location /alexa {

ask = Ask(app, '/')
ask = Ask(app, '/alexa/')

3.(选项?)重新安装pyOpenSSL

如果你有这样的错误......

AttributeError: module 'lib' has no attribute 'X509V3_EXT_get'

重新安装 pyOpenSSL。我安装了 pyOpenSSL 19.0.0。

终端
pip3 uninstall pyOpenSSL
pip3 install pyOpenSSL
于 2019-05-15T14:42:43.857 回答