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

Cannot load CORS content #38

Closed
Resisty opened this issue Jul 31, 2014 · 7 comments
Closed

Cannot load CORS content #38

Resisty opened this issue Jul 31, 2014 · 7 comments

Comments

@Resisty
Copy link

Resisty commented Jul 31, 2014

Hello, I happened across your project after banging my head against trying to make an XMLHttpRequest in my javascript against my flask code (running on the same server, ports 8000 and 5000, respectively). No matter what I try, nothing gets past the "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access." error. From flask:

8 from flask.ext.cors import cross_origin
...
39 @app.route('/character_scrape', methods=['GET', 'POST'])
40 @cross_origin(headers=['Content-Type'])
41 @on_subnet
42 def scrape_char():

Thanks for your time!

@corydolphin
Copy link
Owner

Hi there, sorry to hear you are having trouble.

I would love to try and help, can you help me to confirm that there are no CORS headers being returned?

If you run your Flask server, and curl the headers:
curl -I http://127.0.0.1:5000/character_scrape

What is returned? Also, can you confirm that your scrape_char route is not erroring out? Currently, if an unhandled exception occurs, then Flask-Cors is not involved in returning the 500 response, and thus it will not contain CORS headers. This can be tricky to debug, and I will be changing it in the future.

@Resisty
Copy link
Author

Resisty commented Jul 31, 2014

Hey, thanks for the fast response! Here's what I see:

brianauron@Resisty ~/character_scraper % curl -I http://127.0.0.1:5000/character_scrape
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 77
Server: Werkzeug/0.9.6 Python/2.7.6
Date: Thu, 31 Jul 2014 01:22:39 GMT

To make sure the endpoint actually works, I've been using wget:
brianauron@Resisty ~/character_scraper % wget -qO- --post-data="character=Alaali&realm=cenarius" localhost:5000/character_scrape
{
"class": "Shaman",
"level": "90",
"race": "Draenei",
"spec tip": "Elemental"
}

which is correct data.

If it matters, I don't see anything unusual in the Flask debug log.

@Resisty
Copy link
Author

Resisty commented Jul 31, 2014

I think the last time I posted my code was in a revision without your module. Just now, I tried with telnet:

brianauron@Resisty ~/character_scraper % telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /character_scrape HTTP/1.1

HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 77
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Server: Werkzeug/0.9.6 Python/2.7.6
Date: Thu, 31 Jul 2014 01:55:44 GMT

{
"class": "N/A",
"level": "0",
"race": "N/A",
"spec tip": "N/A"
}

@corydolphin
Copy link
Owner

@Resisty that looks like the CORS headers are being sent correctly. Can you confirm that the problem is resolved?

@Resisty
Copy link
Author

Resisty commented Jul 31, 2014

@wcdolphin No, sorry. Those headers show up in curl/telnet/etc but chrome web developer still shows the no header error and the content fails to show up.

@corydolphin
Copy link
Owner

Okay, no worries, we will get to the bottom of this! Can you help me by answer a few questions and verify a few of my assumptions?

So presumably you are hosting some HTML/JS from a webserver (eg node http-server, or similar) on port 8000 which is making an AJAX request to a flask app running on 5000, is that correct?

  1. I see that one of your url params is 'realm', is this service intended to be behind HTTP Auth?
  2. In the chrome developer console, can you confirm what the AJAX request headers and response are? Is the content what you expect? The status code what you expect?

@Resisty
Copy link
Author

Resisty commented Jul 31, 2014

Hi @wcdolphin I really appreciate all the help, but I've just changed my code to rely solely on Flask and not at all on a separate service. Given everything I've tried tonight I think most of this issue is me and not your project, so don't worry about it.

Thanks again!

@Resisty Resisty closed this as completed Jul 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants