Page 4 of 4

Re: Open subtitles API download issue

Posted: Fri Apr 14, 2023 7:21 am
by qacomohibeb
This seems to be the problem. Thanks.

However, note that the code examples show either Bearer or Key authorization.
E.g.

Code: Select all

curl --request POST \ --url https://api.opensubtitles.com/api/v1/download \ --header 'Authorization: Bearer xyz' \ --header 'Content-Type: application/json' \ --data '{ "file_id": 123 }'
and:

Code: Select all

curl --request POST \ --url https://api.opensubtitles.com/api/v1/download \ --header 'Api-Key: x' \ --header 'Content-Type: application/json' \ --data '{ "file_id": 123 }'

Re: Open subtitles API download issue

Posted: Fri Apr 14, 2023 9:49 am
by os_dev
This seems to be the problem. Thanks.

However, note that the code examples show either Bearer or Key authorization.
E.g.

Code: Select all

curl --request POST \ --url https://api.opensubtitles.com/api/v1/download \ --header 'Authorization: Bearer xyz' \ --header 'Content-Type: application/json' \ --data '{ "file_id": 123 }'
and:

Code: Select all

curl --request POST \ --url https://api.opensubtitles.com/api/v1/download \ --header 'Api-Key: x' \ --header 'Content-Type: application/json' \ --data '{ "file_id": 123 }'
So, in all documentation, the instructions take precedence over the examples. The documentation system generates the curl examples, and he won't let us put 2 authentication methods in the header.

that's why we put that message on top "In HTTP request must be both headers: Api-Key and Authorization"

Re: Open subtitles API download issue

Posted: Fri Apr 14, 2023 6:15 pm
by oss
I will update documentation, that example on the right is not correct because limitations of stoplight.io

Re: Open subtitles API download issue

Posted: Sun Apr 16, 2023 7:08 am
by RazerBlader
I've been struggling to successfully download files with the API, even with both 'Authorization' and 'API-Key' verification methods in the header. I'm working in python and am new to using API's, so my apologies if I'm making a silly error.

Here is the code I am using to try to connect and download a subtitle file from a subtitle id (in this case 1860215).

Code: Select all

import http.client conn = http.client.HTTPSConnection("api.opensubtitles.com") payload = "{\n \"file_id\": 1860215\n}" headers = { "Content-Type": "application/json", "Authorization": "Bearer {}", "Api-Key": "{}".format(api_key,api_key) } conn.request("POST", "/api/v1/download", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
I've tried quite a lot of different ways of doing it, with different authentication methods and with requests instead of client, but nothing is working properly. I am currently getting this error: "message":"The upstream server is timing out".

Using the previous url https://www.opensubtitles.com/api/v1/login I've managed to get a script working, but it stops working after a set number of requests (I understand that this is intentional and is being depreciated).

Please can someone help me figure out what is going wrong. Many thanks!

Re: Open subtitles API download issue

Posted: Sun Apr 16, 2023 3:34 pm
by oss
Hi

we are not python programmers, but here it seems you sending EMPTY Bearer ?

headers = { "Content-Type": "application/json", "Authorization": "Bearer {}", "Api-Key": "{}".format(api_key,api_key) }

the best way is to use INSOMNIA or POSTMAN - it is really good. Then you can send CURL examples, so I can just copy and paste it in terminal and it is more visible what actual data you are sending

API works, there are around 1000 requests per second to it right now.

Re: Open subtitles API download issue

Posted: Mon Apr 17, 2023 6:09 am
by RazerBlader
Thanks for the info, played around with Postman and managed to find/fix the issue. I was using the Api-Key for both verification methods instead of using the JWT as the token.

Re: Open subtitles API download issue

Posted: Wed Apr 19, 2023 3:10 pm
by oss
glad you solved it.