How to enable CORS on Google App Engine Python Server?

For a python script you can add the following line near other self.response.header lines.

self.response.headers['Access-Control-Allow-Origin'] = '*'

This worked for me. The idea was taken from a php issue listed in the notes of another answer.


You'll have to use the Access-Control-Allow-Origin http header in your yaml configuration

handlers:
- url: /
  ...
  http_headers:
    Access-Control-Allow-Origin: http://my-url

Find more under CORS Support in the docs


For those who are wondering how to basically allow all origins for the AppEngine instance in Springboot:

  • use the @CrossOrigin(origins = "*") annotation on the @RestController classes your project has
  • or use use the same annotation above for any of your specific resource methods that has one of the @GetMapping, @PostMapping, etc annotations.

No need to set any of the handlers in the app.yaml. Actually it didn't work when changing the app.yaml file as explained in the docs

...
...
...

@SpringBootApplication
@RestController
@CrossOrigin(origins = "*")  // <--- here 
public class SpringbootApplication {

 ...
 ...
  @GetMapping("/")      
  @CrossOrigin(origins = "*").     // <--- or here 
  public String hello() {
      .....
  }

}