Forum rules
Under no circumstances is spamming or advertising of any kind allowed. Do not post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate others security. Profanity or any kind of insolent behavior to other members (regardless of rank) will not be tolerated. Remember, what you don’t find offensive can be offensive to other members. Please treat each other with the kind of reverence you’d expect from other members.
Failure to comply with any of the above will result in users being banned without notice. If any further details are needed, contact: “The team” using the link at the bottom of the forum page. Thank you.
natsunasubi
Posts: 11
Joined: Thu Jun 01, 2023 1:57 pm

CORS ERROR: api.opensubtitles.com

Thu Jun 01, 2023 2:20 pm

Hi, I am using the new API from OpenSubtitles.com from a web browser and JavaScript.
However, I have been able to use it for the past few days, but now I am unable to use it due to a CORS error.
It seems to be caused by the lack of Access-Control-Allow-* in the response from cloudflare.
Is there any way to fix this?

Code: Select all

curl -X OPTIONS \ -v 'https://api.opensubtitles.com/api/v1/subtitles?episode_number=1&languages=en&query=sneaky+pete&season_number=1' \ -H 'Access-Control-Request-Method: GET' \ -H 'Access-Control-Request-Headers: api-key,content-type' \ -H 'Accept: application/json' \ -H 'Api-Key: XXXXXXXXXXXXXXX' \ -H 'Origin: http://localhost'

Code: Select all

< HTTP/2 200 < date: Thu, 01 Jun 2023 12:07:40 GMT < content-length: 0 < accept-ranges: bytes < x-kong-upstream-latency: 1 < x-kong-proxy-latency: 1 < x-cache-backend: apigw1_8000 rb7 < age: 0 < x-var-cache: MISS < x-via: fw1 < cf-cache-status: DYNAMIC < report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=XXXXXXXXX"}],"group":"cf-nel","max_age":604800} < nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} < strict-transport-security: max-age=15552000; includeSubDomains; preload < x-content-type-options: nosniff < server: cloudflare < cf-ray: 7d07566e689b1f57-NRT < alt-svc: h3=":443"; ma=86400
Thank you,

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: CORS ERROR: api.opensubtitles.com

Tue Jun 13, 2023 5:46 pm

ok it should be all fixed now.

natsunasubi
Posts: 11
Joined: Thu Jun 01, 2023 1:57 pm

Re: CORS ERROR: api.opensubtitles.com

Tue Jun 13, 2023 5:49 pm

Thank you!
Last edited by natsunasubi on Tue Jun 13, 2023 5:49 pm, edited 1 time in total.

stavby
Posts: 3
Joined: Sat Aug 26, 2023 1:17 pm

Re: CORS ERROR: api.opensubtitles.com

Sun Aug 27, 2023 9:24 pm

Thank you!
Hi, how did this get resolved for you?
Did they just fix their API?
Because I still get that CORS error same as you did

natsunasubi
Posts: 11
Joined: Thu Jun 01, 2023 1:57 pm

Re: CORS ERROR: api.opensubtitles.com

Tue Aug 29, 2023 11:51 am

Although this issue was resolved once, it seems to have recurred.
As before, it seems to be caused by API's Cloudflare configuration.
The browser's Options-Request seems to be rejected by the part that checks the User-Agent.

==To: OpenSubtitles.com==

1. Options-Request is an automatic browser request that inquires with the server before sending a GET request from a web page to confirm if the request is permitted. And it is not possible to add header information, etc.
Could you modify the configuration not to check the User-Agent in the case of Options-Request?

2. In the case of browsers, User-Agent cannot be changed. Could you also modify the API to check the X-User-Agent?

--------------------
curl -v -X OPTIONS \
--url 'https://api.opensubtitles.com/api/v1/subtitles?episode_number=1&languages=en&query=sneak&season_number=1' \
-H 'Access-Control-Request-Method: GET' \
-H 'Access-Control-Request-Headers: api-key,content-type,x-user-agent'
--------Response--------
...
<h1>Error 403 User-Agent header is wrong; set it to App name with version eg: MyApp v1.2.3</h1>
<p>User-Agent header is wrong; set it to App name with version eg: MyApp v1.2.3</p>
....
--------------------
Last edited by natsunasubi on Tue Aug 29, 2023 11:58 am, edited 2 times in total.

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: CORS ERROR: api.opensubtitles.com

Thu Sep 07, 2023 12:30 pm

Hi

please try now, if it is working for you (should). We implement force checking of proper user-agent in header, but didn't check x-user-agent

natsunasubi
Posts: 11
Joined: Thu Jun 01, 2023 1:57 pm

Re: CORS ERROR: api.opensubtitles.com

Thu Sep 07, 2023 4:01 pm

Hi, thank you for your reply.

I tried it the other day and it worked fine, so I assumed you had taken care of it, but when I tried it now it is not working again.
The reply from Cloudflare to the Options-Request is 403, which results in an error.

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: CORS ERROR: api.opensubtitles.com

Thu Sep 07, 2023 4:26 pm

can you give me example using CURL for option-request which is not working ? In Options, you can also set up X-User-Agent ?

natsunasubi
Posts: 11
Joined: Thu Jun 01, 2023 1:57 pm

Re: CORS ERROR: api.opensubtitles.com

Thu Sep 07, 2023 4:39 pm

Thank you for your reply.

It is not possible to add X-User-Agent or Api-Key in Options-request.
This is because the browser automatically queries the server to see if the API supports calls from external servers.

curl -v -X OPTIONS \
--url 'https://api.opensubtitles.com/api/v1/subtitles?languages=en&query=titanic' \
-H 'Access-Control-Request-Method: GET' \
-H 'Access-Control-Request-Headers: api-key,content-type,x-user-agent' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
Last edited by natsunasubi on Thu Sep 07, 2023 4:43 pm, edited 2 times in total.

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: CORS ERROR: api.opensubtitles.com

Thu Sep 07, 2023 5:17 pm

ok perfect. fixed.

natsunasubi
Posts: 11
Joined: Thu Jun 01, 2023 1:57 pm

Re: CORS ERROR: api.opensubtitles.com

Thu Sep 07, 2023 5:32 pm

Thank you! Perfect!

Return to “Developing”

Who is online

Users browsing this forum: No registered users and 23 guests