Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST request blocked by CORS policy #151

Closed
pvk-developer opened this issue Jul 26, 2019 · 0 comments · Fixed by #150
Closed

POST request blocked by CORS policy #151

pvk-developer opened this issue Jul 26, 2019 · 0 comments · Fixed by #150
Assignees
Labels
Milestone

Comments

@pvk-developer
Copy link
Member

pvk-developer commented Jul 26, 2019

  • ATM version: 0.2.2

Description

When trying to make a POST call to the REST API server from a browser the following error appears:

Access to XMLHttpRequest at 'http://127.0.0.1:5000/api/datasets' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

How to reproduce the error

Just make a POST request to ATM from a browser using a different host name and port than the one that has served the HTML.

The simplest way to achieve this is by creating a simple HTML file with some javascript code that attempts to make a POST to the ATM API Endpoint and then opening that HTML file in the browser.

$ atm start
Starting ATM
$ cat test_post.html 
<html>
  <body>
    <input value="POST" type="button" onclick="post()">
  </body>
  <script>
    function post() {
      var xhr = new XMLHttpRequest();
      xhr.open("POST", "http://127.0.0.1:5000/api/datasets", true);
      xhr.setRequestHeader("Content-Type", "application/json");
      var data = JSON.stringify({
        train_path: 'https://atm-data.s3.amazonaws.com/pollution_1.csv',
        class_column: 'class'
      });
      xhr.send(data);
    }
  </script>
</html>
$ x-www-browser test_post.html
Opening in existing browser session.

Once the file is open in the browser, a POST button will show up.
Click on the POST button, and the error mention above will show in the browser console.

@pvk-developer pvk-developer self-assigned this Jul 26, 2019
@csala csala changed the title POST call from web/html fails. POST request block by CORS policy Jul 26, 2019
@csala csala changed the title POST request block by CORS policy POST request blocked by CORS policy Jul 26, 2019
@csala csala added the bug label Jul 26, 2019
@csala csala modified the milestones: 0.2.1, 0.2.2 Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants