CORS

34 views
Skip to first unread message

chrisdef...@gmail.com

unread,
Jan 27, 2022, 8:28:46 AMJan 27
to SDQL API
Hey Joe, I wrote a React app to test API endpoints.  I can  successfully retrieve and analyze data from flickr, songster and other endpoints.  So I'm just ready to start working with the SDQL API.

This query runs successfully from python and sportsdatabase.com:
  date,team,o:team,points,o:points@date=20220125 and team=Trailblazers

However, when I run from my app with the appropriate headers, I get this error:
  "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://sportsdatabase.com... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

My question:  Are you forbidding browser script access, or is this due to some other issue?

Thanks,

Chris.




Joe Meyer

unread,
Jan 27, 2022, 5:29:11 PMJan 27
to SDQL API
Chris and API Friends,
 
You can use the settings API, as now described on sportsdatabase.com, to set a domain for CORS access.

Please report any issues here, and please address messages to the whole group as many here have excellent knowledge and few are called Joe.

I am looking forward to seeing your site.

Best regards,

Joe Meyer
Sports Database LLC

chrisdef...@gmail.com

unread,
Jan 27, 2022, 8:31:05 PMJan 27
to SDQL API
Thanks for looking into this Joe.  I issued the CORS domain request from Python and received a 200 status.  Unfortunately, the query from my app still fails with the same message:
   ...Reason: CORS header ‘Access-Control-Allow-Origin’ missing

1. Is there a way to check on the existing setting of the CORS domain request?
2. I used an ip address, not a domain name.  Is this an issue?
3. Are any special CORS related headers required in the SDQL request?

Note: my request.method is set to CORS.

Much appreciation,

Chris.

Joe Meyer

unread,
Jan 28, 2022, 1:50:05 PMJan 28
to SDQL API
Chris and SDQL API Friends,

This Python snippet shows how to use the settings API to set  (and check) your 'CORS domain' settings:

    url = "https://sportsdatabase.com/sapi"
    d = { 'CORS domain':'sdql.com'}
    h = {'token':Joe_TOKEN,'client':'Joe','action':'replace'}
    ret = requests.post(url,json=d, headers=h)
    print("ret:",ret.status_code,ret.text,) 
    ret = requests.get(url,headers=h)
    print("ret:",ret.status_code,ret.text,)

Best regards,

Joe  Meyer
Sports Database LLC

chrisdef...@gmail.com

unread,
Jan 28, 2022, 2:16:01 PMJan 28
to SDQL API
Got it, the result was:
ret: 200 {"success": "settings", "action": "replace"}
ret: 200 {'CORS domain': 'MY.IP.ADD.RESS'}

But, the error message is the same. 
2. I looked up the "Access-Control-Allow-Origin" response header and it looks like you may need to set it to * or the CORS domain--not sure which is appropriate.

Feel free to contact me directly if you want to test directly with my web app.

Thanks again,

Chris.

Joe Meyer

unread,
Jan 31, 2022, 8:41:51 AMJan 31
to SDQL API
Chris and SDQL API Friends,

I see that CORS is working as expected, for example, at:

If you are still having trouble, my best suggestion is that you kindly ask this group for help.
Several others have already successfully used the SDQL API to build really nice apps.

best regards,

Joe Meyer
Sports Database LLC 

Reply all
Reply to author
Forward
0 new messages