Bazarr: "unauthorized" on opensubtitles

Created on 24 Mar 2020  路  30Comments  路  Source: morpheus65535/bazarr

good morning.
i seem to have a little problem:

Throttling opensubtitles for 10 minutes, until 20/03/24 09:19, because of: Unauthorized. Exception info: None

the error is "Unauthorized" all the time.
I tried with linuxserver-bazarr:latest and linuxserver-bazarr:development with same problem
I also made sure my password work, i went to the opensubtitles web and could log in correctly and I have no limitations or anything that could prevent me from getting subs
also tried without a username/password and disabling SSL, same error
this has been going on for a few days now

bug high

Most helpful comment

@pannal is working on a fix.

All 30 comments

+1

Bazarr Version:
0.8.4.3
Sonarr Version:
2.0.0.5344
Radarr Version:
0.2.0.1480
Operating System:
Linux-4.14.24-qnap-x86_64-with
Python Version:
3.8.2
Bazarr Directory:
/app/bazarr
Bazarr Config Directory:
/config

log:
Using opensubtitles again after 10 minutes, (disabled because: Unauthorized)

+1
Bazarr Version:
0.8.4.2
Sonarr Version:
3.0.3.735
Radarr Version:
0.2.0.1480
Operating System:
Linux-5.3.0-42-generic-x86_64-with
Python Version:
3.8.2

Followed by logging :

`   Throttling opensubtitles for 10 minutes, until 20/03/24 11:26, because of: Unauthorized. Exception info: None   
a few seconds ago
    Unexpected error in provider 'opensubtitles': Traceback (most recent call last): File "/app/bazarr/bazarr/../libs/subliminal_patch/core.py", line 168, in list_subtitles_provider results = self[provider].list_subtitles(video, provider_languages) File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 237, in list_subtitles return self.query(languages, hash=video.hashes.get('opensubtitles'), size=video.size, imdb_id=video.imdb_id, File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 270, in query response = self.use_token_or_login( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 161, in use_token_or_login self.log_in() File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 147, in log_in response = self.retry( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/mixins.py", line 47, in retry return f() File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 148, in lambda: checked( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 372, in checked raise Unauthorizedsubliminal.providers.opensubtitles.Unauthorized   
a few seconds ago
    https://api.opensubtitles.org:443 "POST /xml-rpc HTTP/1.1" 200 177  
a few seconds ago
    No subtitles found  
a few seconds ago
    https://www.podnapisi.net:443 "GET /subtitles/search/old?sXML=1&sL=nl&sK=XXXXXXXTS=2&sTE=2&sY=2012 HTTP/1.1" 200 1465   
a few seconds ago
    DNS: Falling back to default DNS or IP on api.opensubtitles.org 
a few seconds ago
    Starting new HTTPS connection (1): api.opensubtitles.org:443    
a few seconds ago
    Searching subtitles [{'moviehash': '1be0110efb9f9424', 'moviebytesize': '2326697573', 'sublanguageid': 'dut'}, {'query': 'XXXXXX', 'season': 2, 'episode': 2, 'sublanguageid': 'dut'}]  
a few seconds ago
    Login failed, please check your credentials 
a few seconds ago
    https://api.opensubtitles.org:443 "POST /xml-rpc HTTP/1.1" 200 177`

Some debugging:

Does not look like an API issue, short python to test Login

from urllib3.packages.six.moves.xmlrpc_client import ServerProxy

server = ServerProxy('https://api.opensubtitles.org/xml-rpc')
response = server.LogIn('############', '##########', 'eng', 'Bazarr/1')

print(response)

criteria = [{'moviehash': '4a64307e8cbf1cf5', 'moviebytesize': '1506506055', 'sublanguageid': 'spa'}, {'imdbid': '8579674', 'sublang
uageid': 'spa'}, {'query': '1917', 'sublanguageid': 'spa'}, {'query': 'April 6 1917', 'sublanguageid': 'spa'}]

reponse = server.SearchSubtitles(response['token'], criteria)

print(reponse)

Somethig odd I've found in the logs:

2020-03-24 17:02:46,451 - subliminal_patch.providers.opensubtitles (7f8e0cf11700) :  DEBUG (opensubtitles:184) - Trying previous token: '<dogpile.cXXXXXXXXXXXXXXXXXXXXXXXX'

This does not look like a token, anyway it tries to use my credentials and fails.

Thanks @GermanG for looking at it. If you are able to go further in your investigation, it would be greatly appreciated! I'm a bit overwhelmed by work with the actual crisis. :-/

Some problem, password is working on the website.

some debug logging;

24/03/2020 19:18:44|INFO |subliminal_patch.core |Initializing provider opensubtitles|
24/03/2020 19:18:44|DEBUG |subliminal_patch.providers.opensubtitles|Using timeout: 15|
24/03/2020 19:18:44|DEBUG |subliminal_patch.providers.opensubtitles|Using HTTPS connection|
24/03/2020 19:18:44|INFO |subliminal_patch.providers.opensubtitles|Logging in|
24/03/2020 19:18:44|DEBUG |subliminal_patch.providers.opensubtitles|Trying previous token: 'bytearray(XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'|
24/03/2020 19:18:44|DEBUG |urllib3.connectionpool |Starting new HTTPS connection (1): api.opensubtitles.org:443|
24/03/2020 19:18:44|DEBUG |subliminal_patch.http |DNS: Falling back to default DNS or IP on api.opensubtitles.org|
24/03/2020 19:18:44|DEBUG |urllib3.connectionpool |https://api.opensubtitles.org:443 "POST /xml-rpc HTTP/1.1" 200 212|
24/03/2020 19:18:44|DEBUG |subliminal_patch.providers.opensubtitles|Token not valid.|
24/03/2020 19:18:44|DEBUG |urllib3.connectionpool |Starting new HTTPS connection (1): api.opensubtitles.org:443|
24/03/2020 19:18:44|DEBUG |subliminal_patch.http |DNS: Falling back to default DNS or IP on api.opensubtitles.org|
24/03/2020 19:18:44|DEBUG |urllib3.connectionpool |https://api.opensubtitles.org:443 "POST /xml-rpc HTTP/1.1" 200 177|
24/03/2020 19:18:44|ERROR |subliminal_patch.providers.opensubtitles|Login failed, please check your credentials|
24/03/2020 19:18:44|INFO |subliminal_patch.providers.opensubtitles|Searching subtitles [{'moviehash': 'e25e920ecb1eed10', 'moviebytesize': '1743184175', 'sublanguageid': 'dut'}, {'query': 'Chicago Fire', 'season': 8, 'episode': 17, 'sublanguageid': 'dut'}]|
24/03/2020 19:18:44|DEBUG |urllib3.connectionpool |Starting new HTTPS connection (1): api.opensubtitles.org:443|
24/03/2020 19:18:44|DEBUG |subliminal_patch.http |DNS: Falling back to default DNS or IP on api.opensubtitles.org|
24/03/2020 19:18:44|DEBUG |urllib3.connectionpool |https://api.opensubtitles.org:443 "POST /xml-rpc HTTP/1.1" 200 177|
24/03/2020 19:18:44|ERROR |subliminal_patch.core |Unexpected error in provider 'opensubtitles': Traceback (most recent call last): File "/app/bazarr/bazarr/../libs/subliminal_patch/core.py", line 168, in list_subtitles_provider results = self[provider].list_subtitles(video, provider_languages) File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 237, in list_subtitles return self.query(languages, hash=video.hashes.get('opensubtitles'), size=video.size, imdb_id=video.imdb_id, File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 270, in query response = self.use_token_or_login( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 161, in use_token_or_login self.log_in() File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 147, in log_in response = self.retry( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/mixins.py", line 47, in retry return f() File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 148, in lambda: checked( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 372, in checked raise Unauthorizedsubliminal.providers.opensubtitles.Unauthorized|Traceback (most recent call last): File "/app/bazarr/bazarr/../libs/subliminal_patch/core.py", line 168, in list_subtitles_provider results = self[provider].list_subtitles(video, provider_languages) File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 237, in list_subtitles return self.query(languages, hash=video.hashes.get('opensubtitles'), size=video.size, imdb_id=video.imdb_id, File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 270, in query response = self.use_token_or_login( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 161, in use_token_or_login self.log_in() File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 147, in log_in response = self.retry( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/mixins.py", line 47, in retry return f() File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 148, in lambda: checked( File "/app/bazarr/bazarr/../libs/subliminal_patch/providers/opensubtitles.py", line 372, in checked raise Unauthorizedsubliminal.providers.opensubtitles.Unauthorized|
24/03/2020 19:18:44|INFO |root |Throttling opensubtitles for 10 minutes, until 20/03/24 19:28, because of: Unauthorized. Exception info: None|
24/03/2020 19:18:44|INFO |subliminal_patch.core |Discarding provider opensubtitles|
24/03/2020 19:18:44|INFO |subliminal_patch.core |Found 0 subtitle(s)|`

windows version also stop working

I have a hack that "fixes" it, in libs/subliminal_patch/providers/opensubtitles.py, line 138:

  def get_server_proxy(self, url, timeout=None):
        return ServerProxy(url, SubZeroRequestsTransport(use_https=self.use_ssl, timeout=timeout or self.timeout, user_agent='Python-xmlrpc/3.8'))

Basically change the User Agent in ServerProxy.
It's a hack and it's not a real fix, we should have the user agent fixed on opensubtitles side.

EDIT: changed the fix to reflect my https://github.com/morpheus65535/bazarr/issues/881#issuecomment-603754008

It's a hack and it's not a real fix, I need to understand what SubZeroRequestsTransport does.

Thanks for taking the time to look into it. It's our most used provider with about 45% of download.

@pannal this one should be problematic for you in sub-zero.

The main issue I see so far is the lack of user-agent header in the requests (will go as 'Python-xmlrpc/3.8'), which is a no-no.
Edit: SubZeroRequestsTransport is a requests based replacement for the default httplib in xmlrpc.

Edit2
A non working example without SubZeroRequestsTransport:

import sys
# sys.path.append ('libs')

from urllib3.packages.six.moves.xmlrpc_client import ServerProxy
# from subliminal_patch.http import SubZeroRequestsTransport

import requests
import xmlrpc.client

class RequestsTransport(xmlrpc.client.Transport):

    def request(self, host, handler, data, verbose=False):
        # set the headers, including the user-agent
        headers = {"User-Agent": "Bazarr/1",
                   "Content-Type": "text/xml",
                   "Accept-Encoding": "gzip"}
        url = "https://%s%s" % (host, handler)
        try:
            response = None
            response = requests.post(url, data=data, headers=headers, stream=True)
            response.raise_for_status()
            return self.parse_response(response)
        except requests.RequestException as e:
            if response is None:
                raise xmlrpc.client.ProtocolError(url, 500, str(e), "")
            else:
                raise xmlrpc.client.ProtocolError(url, response.status_code,
                                                  str(e), response.headers)

    def parse_response(self, resp):
        """
        Parse the xmlrpc response.
        """
        p, u = self.getparser()
        p.feed(resp.text)
        p.close()
        return u.close()

server = ServerProxy('https://api.opensubtitles.org/xml-rpc', RequestsTransport())
# SubZeroRequestsTransport(use_https=True, timeout=10, user_agent='Bazarr/1')
response = server.LogIn('########', '#########', 'Bazarr/1') 

print(response)

@morpheus65535 I was referring to my "fix".
Anyway, Bazarr User-Agent is blocked. I don't know what I did wrong on my first try (changing it), but using Python original UA works:
```
return ServerProxy(url, SubZeroRequestsTransport(use_https=self.use_ssl, timeout=timeout or self.timeout, user_agent='Python-xmlrpc/3.8'))
````
Maybe @pannal has the same issue, I tried "Sub-Zero/2" and failed too.

EDIT: @morpheus65535 did you register the User Agent as described in https://trac.opensubtitles.org/projects/opensubtitles/wiki/DevReadFirst ?

@GermanG yes it's been done in January of last year. I've wrote an email to OS admin to have more informations about the current status of my user agent as there is no mention of anything on the web site.

@morpheus65535 I've made a curl command to show it's the UA (replace Bazarr/1 with Python-xmlrpc/3.8):

curl -v -X POST -H 'Accept: */*' -H 'Connection: keep-alive' -H 'Host: api.opensubtitles.org' -H 'Accept-Encoding: gzip' -H 'Content-Type: text/xml' -H 'User-Agent: Bazarr/1' --data "<?xml version='1.0'?><methodCall><methodName>LogIn</methodName><params><param><value><string>YOURUSERNAME</string></value></param><param><value><string>YOURPASSWORD</string></value></param><param><value><string>eng</string></value></param><param><value><string>Bazarr/1</string></value></param></params></methodCall>" 'http://api.opensubtitles.org/xml-rpc' --output - | gunzip - | xmllint --format -

On the other hand, I've read somewhere (don't remember where) that you can use the username as UA, that might be a solution too.

@pannal is working on a fix.

hi all, we was forced to changed some authorization for some user agents (UAs which used totally 80% of all requests), so now during corona virus outbreak our servers was overloaded. To free up load we decided to require user authorization (username and password used on opensubtitles.org), so it will work. I did some debug (simple LogIn and SearchSubtitles on xml-rpc with Bazarr UA and it works here).

Basically you have to insert username and password into LogIn() API method and then it will works. User have to register on our site www.opensubtitles.org

And please don't "hack" UA, this is leading nowhere.

I'm still seeing an 'unauthorized' error, even though I used my correct login details in Bazarr's settings. Should I do something different?

@opensubtitles
i was already using user/pass when i detected this bug in the first place.
i can't test right now, but unless something has changed in the past 24h. this is still not working, like @Orbeatle said.

just tested it again - using user/pass - still getting unauthorized

@opensubtitles Thanks for taking the time to comment this issue. I agree with you that we must not try to "hack" the UA as a permanent solution and was refering to this as a temporary fix while we try to make things work like they should.

Now that we are aware of a change on your side, I can confirm that only adding username and password while calling the LogIn method doesn't change the resulting 401. You can test with curl:

curl -v -X POST -H 'Accept: */*' -H 'Connection: keep-alive' -H 'Host: api.opensubtitles.org' -H 'Accept-Encoding: gzip' -H 'Content-Type: text/xml' -H 'User-Agent: Bazarr/1' --data "<?xml version='1.0'?><methodCall><methodName>LogIn</methodName><params><param><value><string>USERNAME</string></value></param><param><value><string>PASSWORD</string></value></param><param><value><string>eng</string></value></param><param><value><string>Bazarr/1</string></value></param></params></methodCall>" 'http://api.opensubtitles.org/xml-rpc' --output - | gunzip - | xmllint --format -

Are you sure there is nothing else required?

hi guys, there was problem with http user agent, it would work if...anyway, I fixed it now, so should work please confirm.

@opensubtitles still getting the same result:

<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>token</name>
            <value>
              <string>aaaaaaaaaaaaaaaaaaaaaaaaa</string>
            </value>
          </member>
          <member>
            <name>status</name>
            <value>
              <string>401 Unauthorized</string>
            </value>
          </member>
          <member>
            <name>seconds</name>
            <value>
              <double>0.016</double>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>

I'm now seeing another error: Throttling opensubtitles for 20 minutes, until 20/03/26 14:47, because of: ServiceUnavailable. Exception info: '503'

Opensubtitles is working again for me..

Maybe sometime required to sync things on their side. Working in Bazarr now if you have a username/password set. :-)

Yes, got it working again too. Restarted the service and reenabled opensubitles.
Cool!

Opensubtitles is working again on Bazarr.

Cheers!

@morpheus65535 @opensubtitles can confirm, with user&pass it's working again.
thanks for the help and solution

Thanks all for the confirmation!

Was this page helpful?
0 / 5 - 0 ratings