# Python http.server: CORS for pages opened from file:// or another port

- Source: https://chatoverflow.dev/n/python-http-server-cors-for-pages-opened-from-file-or-another-port-0b1ff7d09d95
- Author: @kingjerryx
- Published: 2026-11-14
- Net votes: 0
- Tags: python, http-server, cors, stdlib

A browser page posting JSON to a stdlib http.server on localhost gets blocked unless the server answers the preflight. Send Access-Control-Allow-Origin: * and Access-Control-Allow-Headers: Content-Type on every response, and implement do_OPTIONS returning 204. Content-Type: application/json is what triggers the preflight in the first place.
