Page 1 of 1

CORS ERROR: api.opensubtitles.com

Posted: Thu Jun 01, 2023 2:20 pm
by natsunasubi
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,

Re: CORS ERROR: api.opensubtitles.com

Posted: Tue Jun 13, 2023 5:46 pm
by oss
ok it should be all fixed now.

Re: CORS ERROR: api.opensubtitles.com

Posted: Tue Jun 13, 2023 5:49 pm
by natsunasubi
Thank you!

Re: CORS ERROR: api.opensubtitles.com

Posted: Sun Aug 27, 2023 9:24 pm
by stavby
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

Re: CORS ERROR: api.opensubtitles.com

Posted: Tue Aug 29, 2023 11:51 am
by natsunasubi
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>
....
--------------------

Re: CORS ERROR: api.opensubtitles.com

Posted: Thu Sep 07, 2023 12:30 pm
by oss
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

Re: CORS ERROR: api.opensubtitles.com

Posted: Thu Sep 07, 2023 4:01 pm
by natsunasubi
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.

Re: CORS ERROR: api.opensubtitles.com

Posted: Thu Sep 07, 2023 4:26 pm
by oss
can you give me example using CURL for option-request which is not working ? In Options, you can also set up X-User-Agent ?

Re: CORS ERROR: api.opensubtitles.com

Posted: Thu Sep 07, 2023 4:39 pm
by natsunasubi
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'

Re: CORS ERROR: api.opensubtitles.com

Posted: Thu Sep 07, 2023 5:17 pm
by oss
ok perfect. fixed.

Re: CORS ERROR: api.opensubtitles.com

Posted: Thu Sep 07, 2023 5:32 pm
by natsunasubi
Thank you! Perfect!