【问题标题】:Flask Cors not working from Angular APP in python3.10 and macOSFlask Cors 在 python3.10 和 macOS 中无法从 Angular APP 工作
【发布时间】:2022-11-10 21:31:06
【问题描述】:

我已经阅读了几乎所有与 flask 和 flask_cors 相关的问题,但我仍然没有弄清楚发生了什么。

我创建了一个带有角度前端和后端烧瓶的应用程序。它与python3.8和Ubuntu作为计算机的操作系统完美配合。

现在,我搬到了 macOS 和 python3.10 并且 CORS 不允许我提出请求。

后端:

...

from flask_cors import CORS
...


app = Flask(__name__)
cors = CORS(app)


唯一需要考虑的“奇怪”的事情是我添加了一个装饰器来检查每个请求中的令牌,如下所示。

class Auth:
    def check_origin(function):
        @wraps(function)
        def wrapper():
            try:
                ...
            except:
                return Response.error("Origin not recognized", 400)
            return function()

        return wrapper

@app.route("/question", methods=["GET"])
@Auth.check_origin
def get_questions():
    ...

感谢您的阅读!

【问题讨论】:

  • 更新我正在尝试使用 chrome 的前端,来自 Firefox,它运行良好。

标签: python flask flask-cors


【解决方案1】:

我有完全相同的问题。当我使用标志 --host '0.0.0.0' 运行烧瓶应用程序时,显示以下消息:

Address already in use
Port 5000 is in use by another program. Either identify and stop that program, or start the server with a different port.
On macOS, try disabling the 'AirPlay Receiver' service from System Preferences -> Sharing.

我禁用了 AirPlay 接收器,CORS 请求开始起作用。

【讨论】:

    猜你喜欢
    • 2015-06-16
    • 2018-01-18
    • 2018-04-15
    • 1970-01-01
    • 2022-08-17
    • 2020-12-09
    • 1970-01-01
    • 2021-08-02
    • 2021-05-02
    相关资源
    最近更新 更多