python network_error ai_generated true

Access to fetch at 'http://api.local/x' from origin 'http://web.local' has been blocked by CORS policy: Response to preflight request doesn't pass access control check

ID: python/flask-cors-blocked-preflight

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-12-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.x active — — —
5.x active — — —

Root Cause

Flask-CORS not configured for the route, or OPTIONS preflight handled by a catch-all before CORS middleware.

generic

中文

Flask-CORS未针对该路由配置,或者OPTIONS预检被CORS中间件之前的catch-all处理。

Workarounds

  1. 92% success
    CORS(app, resources={r'/api/*': {'origins': ['http://web.local']}}, supports_credentials=True)
  2. 90% success
    app = Flask(__name__)\nCORS(app)\n# then register blueprints

Dead Ends

Common approaches that don't work:

  1. 75% fail

    Preflight OPTIONS never reaches the view; browser blocks it earlier.

  2. 70% fail

    If credentials used, wildcard origin is rejected by the browser.