We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[APP SUBMITTED]: qBittorrent: Unable to set priority for Torrent

### INFO
**Python Version**: `3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.18362-SP0`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@d0c136d7a528a471b51676140bd35d24d97f65c6
**Link to Log**: **No Log available**
### ERROR
<pre>
2019-12-29 19:19:49 ERROR    SNATCHQUEUE-SNATCH-161511 :: [d0c136d] qBittorrent: Unable to set priority for Torrent
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `medusa/clients/torrent/qbittorrent.py`
Content:
```
1 # coding=utf-8
2 
3 """qBittorrent Client."""
4 
5 from __future__ import unicode_literals
6 
7 import logging
8 
9 from medusa import app
10 from medusa.clients.torrent.generic import GenericClient
11 from medusa.logger.adapters.style import BraceAdapter
12 
13 from requests.auth import HTTPDigestAuth
14 from requests.compat import urljoin
15 
16 log = BraceAdapter(logging.getLogger(__name__))
17 log.logger.addHandler(logging.NullHandler())
18 
19 
20 class APIUnavailableError(Exception):
21     """Raised when the API version is not available."""
22 
23 
24 class QBittorrentAPI(GenericClient):
25     """qBittorrent API class."""
26 
27     def __init__(self, host=None, username=None, password=None):
28         """Constructor.
29 
30         :param host:
31         :type host: string
32         :param username:
33         :type username: string
34         :param password:
35         :type password: string
36         """
37         super(QBittorrentAPI, self).__init__('qBittorrent', host, username, password)
38         self.url = self.host
39         # Auth for API v1.0.0 (qBittorrent v3.1.x and older)
40         self.session.auth = HTTPDigestAuth(self.username, self.password)
41 
42         self.api = None
43 
44     def _get_auth(self):
45         """Authenticate with the client using the most recent API version available for use."""
46         try:
47             auth = self._get_auth_v2()
48             version = 2
49         except APIUnavailableError:
50             auth = self._get_auth_legacy()
51             version = 1
52 
53         if not auth:
54             # Authentication failed
55             return auth
56 
57         # Get API version
58         if version == 2:
59             self.url = urljoin(self.host, 'api/v2/app/webapiVersion')
60             try:
61                 response = self.session.get(self.url, verify=app.TORRENT_VERIFY_CERT)
62                 if not response.text:
63                     raise ValueError('Response from client is empty. [Status: {0}]'.format(response.status_code))
64                 # Make sure version is using the (major, minor, release) format
65                 version = tuple(map(int, response.text.split('.')))
66                 # Fill up with zeros to get the correct format. e.g: (2, 3) => (2, 3, 0)
67                 self.api = version + (0,) * (3 - len(version))
68             except (AttributeError, ValueError) as error:
69                 log.error('{name}: Unable to get API version. Error: {error!r}',
70                           {'name': self.name, 'error': error})
71         elif version == 1:
72             try:
73                 self.url = urljoin(self.host, 'version/api')
74                 version = int(self.session.get(self.url, verify=app.TORRENT_VERIFY_CERT).text)
75                 # Convert old API versioning to new versioning (major, minor, release)
76                 self.api = (1, version % 100, 0)
77             except Exception:
78                 self.api = (1, 0, 0)
79 
80         return auth
81 
82     def _get_auth_v2(self):
83         """Authenticate using API v2."""
84         self.url = urljoin(self.host, 'api/v2/auth/login')
85         data = {
86             'username': self.username,
87             'password': self.password,
88         }
89         try:
90             self.response = self.session.post(self.url, data=data, verify=app.TORRENT_VERIFY_CERT)
91         except Exception as error:
92             log.warning('{name}: Exception while trying to authenticate: {error}',
93                         {'name': self.name, 'error': error}, exc_info=1)
94             return None
95 
96         if self.response.status_code == 200:
97             if self.response.text == 'Fails.':
98                 log.warning('{name}: Invalid Username or Password, check your config',
99                             {'name': self.name})
100                 return None
101 
102             # Successful log in
103             self.session.cookies = self.response.cookies
104             self.auth = self.response.text
105 
106             return self.auth
107 
108         if self.response.status_code == 404:
109             # API v2 is not available
110             raise APIUnavailableError()
111 
112         if self.response.status_code == 403:
113             log.warning('{name}: Your IP address has been banned after too many failed authentication attempts.'
114                         ' Restart {name} to unban.',
115                         {'name': self.name})
116             return None
117 
118     def _get_auth_legacy(self):
119         """Authenticate using legacy API."""
120         self.url = urljoin(self.host, 'login')
121         data = {
122             'username': self.username,
123             'password': self.password,
124         }
125         try:
126             self.response = self.session.post(self.url, data=data, verify=app.TORRENT_VERIFY_CERT)
127         except Exception as error:
128             log.warning('{name}: Exception while trying to authenticate: {error}',
129                         {'name': self.name, 'error': error}, exc_info=1)
130             return None
131 
132         # API v1.0.0 (qBittorrent v3.1.x and older)
133         if self.response.status_code == 404:
134             try:
135                 self.response = self.session.get(self.host, verify=app.TORRENT_VERIFY_CERT)
136             except Exception as error:
137                 log.warning('{name}: Exception while trying to authenticate: {error}',
138                             {'name': self.name, 'error': error}, exc_info=1)
139                 return None
140 
141         self.session.cookies = self.response.cookies
142         self.auth = (self.response.status_code != 404) or None
143 
144         return self.auth
145 
146     def _add_torrent_uri(self, result):
147 
148         command = 'api/v2/torrents/add' if self.api >= (2, 0, 0) else 'command/download'
149         self.url = urljoin(self.host, command)
150         data = {
151             'urls': result.url,
152         }
153         return self._request(method='post', data=data, cookies=self.session.cookies)
154 
155     def _add_torrent_file(self, result):
156 
157         command = 'api/v2/torrents/add' if self.api >= (2, 0, 0) else 'command/upload'
158         self.url = urljoin(self.host, command)
159         files = {
160             'torrents': result.content
161         }
162         return self._request(method='post', files=files, cookies=self.session.cookies)
163 
164     def _set_torrent_label(self, result):
165 
166         label = app.TORRENT_LABEL_ANIME if result.series.is_anime else app.TORRENT_LABEL
167         if not label:
168             return True
169 
170         api = self.api
171         if api >= (2, 0, 0):
172             self.url = urljoin(self.host, 'api/v2/torrents/setCategory')
173             label_key = 'category'
174         elif api > (1, 6, 0):
175             label_key = 'Category' if api >= (1, 10, 0) else 'Label'
176             self.url = urljoin(self.host, 'command/set' + label_key)
177 
178         data = {
179             'hashes': result.hash.lower(),
180             label_key.lower(): label.replace(' ', '_'),
181         }
182         ok = self._request(method='post', data=data, cookies=self.session.cookies)
183 
184         if self.response.status_code == 409:
185             log.warning('{name}: Unable to set torrent label. You need to create the label '
186                         ' in {name} first.', {'name': self.name})
187             ok = True
188 
189         return ok
190 
191     def _set_torrent_priority(self, result):
192 
193         command = 'api/v2/torrents' if self.api >= (2, 0, 0) else 'command'
194         method = 'increase' if result.priority == 1 else 'decrease'
195         self.url = urljoin(self.host, '{command}/{method}Prio'.format(command=command, method=method))
196         data = {
197             'hashes': result.hash.lower(),
198         }
199         ok = self._request(method='post', data=data, cookies=self.session.cookies)
200 
201         if self.response.status_code == 403:
202             log.info('{name}: Unable to set torrent priority because torrent queueing'
203                      ' is disabled in {name} settings.', {'name': self.name})
204             ok = True
205 
206         return ok
207 
208     def _set_torrent_pause(self, result):
209         api = self.api
210         state = 'pause' if app.TORRENT_PAUSED else 'resume'
211         command = 'api/v2/torrents' if api >= (2, 0, 0) else 'command'
212         hashes_key = 'hashes' if self.api >= (1, 18, 0) else 'hash'
213         self.url = urljoin(self.host, '{command}/{state}'.format(command=command, state=state))
214         data = {
215             hashes_key: result.hash.lower(),
216         }
217         return self._request(method='post', data=data, cookies=self.session.cookies)
218 
219     def remove_torrent(self, info_hash):
220         """Remove torrent from client using given info_hash.
221 
222         :param info_hash:
223         :type info_hash: string
224         :return
225         :rtype: bool
226         """
227         data = {
228             'hashes': info_hash.lower(),
229         }
230         if self.api >= (2, 0, 0):
231             self.url = urljoin(self.host, 'api/v2/torrents/delete')
232             data['deleteFiles'] = True
233         else:
234             self.url = urljoin(self.host, 'command/deletePerm')
235 
236         return self._request(method='post', data=data, cookies=self.session.cookies)
237 
238 
239 api = QBittorrentAPI
240
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/medusa/clients/torrent/qbittorrent.py b/medusa/clients/torrent/qbittorrent.py
--- a/medusa/clients/torrent/qbittorrent.py
+++ b/medusa/clients/torrent/qbittorrent.py
@@ -198,7 +198,7 @@
         }
         ok = self._request(method='post', data=data, cookies=self.session.cookies)
 
-        if self.response.status_code == 403:
+        if self.response.status_code == (409 if self.api >= (2, 0, 0) else 403):
             log.info('{name}: Unable to set torrent priority because torrent queueing'
                      ' is disabled in {name} settings.', {'name': self.name})
             ok = True

{"golden_diff": "diff --git a/medusa/clients/torrent/qbittorrent.py b/medusa/clients/torrent/qbittorrent.py\n--- a/medusa/clients/torrent/qbittorrent.py\n+++ b/medusa/clients/torrent/qbittorrent.py\n@@ -198,7 +198,7 @@\n         }\n         ok = self._request(method='post', data=data, cookies=self.session.cookies)\n \n-        if self.response.status_code == 403:\n+        if self.response.status_code == (409 if self.api >= (2, 0, 0) else 403):\n             log.info('{name}: Unable to set torrent priority because torrent queueing'\n                      ' is disabled in {name} settings.', {'name': self.name})\n             ok = True\n", "issue": "[APP SUBMITTED]: qBittorrent: Unable to set priority for Torrent\n\n### INFO\n**Python Version**: `3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]`\n**Operating System**: `Windows-10-10.0.18362-SP0`\n**Locale**: `cp1252`\n**Branch**: [master](../tree/master)\n**Database**: `44.14`\n**Commit**: pymedusa/Medusa@d0c136d7a528a471b51676140bd35d24d97f65c6\n**Link to Log**: **No Log available**\n### ERROR\n<pre>\n2019-12-29 19:19:49 ERROR    SNATCHQUEUE-SNATCH-161511 :: [d0c136d] qBittorrent: Unable to set priority for Torrent\n</pre>\n---\n_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators\n\n", "before_files": [{"content": "# coding=utf-8\n\n\"\"\"qBittorrent Client.\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport logging\n\nfrom medusa import app\nfrom medusa.clients.torrent.generic import GenericClient\nfrom medusa.logger.adapters.style import BraceAdapter\n\nfrom requests.auth import HTTPDigestAuth\nfrom requests.compat import urljoin\n\nlog = BraceAdapter(logging.getLogger(__name__))\nlog.logger.addHandler(logging.NullHandler())\n\n\nclass APIUnavailableError(Exception):\n    \"\"\"Raised when the API version is not available.\"\"\"\n\n\nclass QBittorrentAPI(GenericClient):\n    \"\"\"qBittorrent API class.\"\"\"\n\n    def __init__(self, host=None, username=None, password=None):\n        \"\"\"Constructor.\n\n        :param host:\n        :type host: string\n        :param username:\n        :type username: string\n        :param password:\n        :type password: string\n        \"\"\"\n        super(QBittorrentAPI, self).__init__('qBittorrent', host, username, password)\n        self.url = self.host\n        # Auth for API v1.0.0 (qBittorrent v3.1.x and older)\n        self.session.auth = HTTPDigestAuth(self.username, self.password)\n\n        self.api = None\n\n    def _get_auth(self):\n        \"\"\"Authenticate with the client using the most recent API version available for use.\"\"\"\n        try:\n            auth = self._get_auth_v2()\n            version = 2\n        except APIUnavailableError:\n            auth = self._get_auth_legacy()\n            version = 1\n\n        if not auth:\n            # Authentication failed\n            return auth\n\n        # Get API version\n        if version == 2:\n            self.url = urljoin(self.host, 'api/v2/app/webapiVersion')\n            try:\n                response = self.session.get(self.url, verify=app.TORRENT_VERIFY_CERT)\n                if not response.text:\n                    raise ValueError('Response from client is empty. [Status: {0}]'.format(response.status_code))\n                # Make sure version is using the (major, minor, release) format\n                version = tuple(map(int, response.text.split('.')))\n                # Fill up with zeros to get the correct format. e.g: (2, 3) => (2, 3, 0)\n                self.api = version + (0,) * (3 - len(version))\n            except (AttributeError, ValueError) as error:\n                log.error('{name}: Unable to get API version. Error: {error!r}',\n                          {'name': self.name, 'error': error})\n        elif version == 1:\n            try:\n                self.url = urljoin(self.host, 'version/api')\n                version = int(self.session.get(self.url, verify=app.TORRENT_VERIFY_CERT).text)\n                # Convert old API versioning to new versioning (major, minor, release)\n                self.api = (1, version % 100, 0)\n            except Exception:\n                self.api = (1, 0, 0)\n\n        return auth\n\n    def _get_auth_v2(self):\n        \"\"\"Authenticate using API v2.\"\"\"\n        self.url = urljoin(self.host, 'api/v2/auth/login')\n        data = {\n            'username': self.username,\n            'password': self.password,\n        }\n        try:\n            self.response = self.session.post(self.url, data=data, verify=app.TORRENT_VERIFY_CERT)\n        except Exception as error:\n            log.warning('{name}: Exception while trying to authenticate: {error}',\n                        {'name': self.name, 'error': error}, exc_info=1)\n            return None\n\n        if self.response.status_code == 200:\n            if self.response.text == 'Fails.':\n                log.warning('{name}: Invalid Username or Password, check your config',\n                            {'name': self.name})\n                return None\n\n            # Successful log in\n            self.session.cookies = self.response.cookies\n            self.auth = self.response.text\n\n            return self.auth\n\n        if self.response.status_code == 404:\n            # API v2 is not available\n            raise APIUnavailableError()\n\n        if self.response.status_code == 403:\n            log.warning('{name}: Your IP address has been banned after too many failed authentication attempts.'\n                        ' Restart {name} to unban.',\n                        {'name': self.name})\n            return None\n\n    def _get_auth_legacy(self):\n        \"\"\"Authenticate using legacy API.\"\"\"\n        self.url = urljoin(self.host, 'login')\n        data = {\n            'username': self.username,\n            'password': self.password,\n        }\n        try:\n            self.response = self.session.post(self.url, data=data, verify=app.TORRENT_VERIFY_CERT)\n        except Exception as error:\n            log.warning('{name}: Exception while trying to authenticate: {error}',\n                        {'name': self.name, 'error': error}, exc_info=1)\n            return None\n\n        # API v1.0.0 (qBittorrent v3.1.x and older)\n        if self.response.status_code == 404:\n            try:\n                self.response = self.session.get(self.host, verify=app.TORRENT_VERIFY_CERT)\n            except Exception as error:\n                log.warning('{name}: Exception while trying to authenticate: {error}',\n                            {'name': self.name, 'error': error}, exc_info=1)\n                return None\n\n        self.session.cookies = self.response.cookies\n        self.auth = (self.response.status_code != 404) or None\n\n        return self.auth\n\n    def _add_torrent_uri(self, result):\n\n        command = 'api/v2/torrents/add' if self.api >= (2, 0, 0) else 'command/download'\n        self.url = urljoin(self.host, command)\n        data = {\n            'urls': result.url,\n        }\n        return self._request(method='post', data=data, cookies=self.session.cookies)\n\n    def _add_torrent_file(self, result):\n\n        command = 'api/v2/torrents/add' if self.api >= (2, 0, 0) else 'command/upload'\n        self.url = urljoin(self.host, command)\n        files = {\n            'torrents': result.content\n        }\n        return self._request(method='post', files=files, cookies=self.session.cookies)\n\n    def _set_torrent_label(self, result):\n\n        label = app.TORRENT_LABEL_ANIME if result.series.is_anime else app.TORRENT_LABEL\n        if not label:\n            return True\n\n        api = self.api\n        if api >= (2, 0, 0):\n            self.url = urljoin(self.host, 'api/v2/torrents/setCategory')\n            label_key = 'category'\n        elif api > (1, 6, 0):\n            label_key = 'Category' if api >= (1, 10, 0) else 'Label'\n            self.url = urljoin(self.host, 'command/set' + label_key)\n\n        data = {\n            'hashes': result.hash.lower(),\n            label_key.lower(): label.replace(' ', '_'),\n        }\n        ok = self._request(method='post', data=data, cookies=self.session.cookies)\n\n        if self.response.status_code == 409:\n            log.warning('{name}: Unable to set torrent label. You need to create the label '\n                        ' in {name} first.', {'name': self.name})\n            ok = True\n\n        return ok\n\n    def _set_torrent_priority(self, result):\n\n        command = 'api/v2/torrents' if self.api >= (2, 0, 0) else 'command'\n        method = 'increase' if result.priority == 1 else 'decrease'\n        self.url = urljoin(self.host, '{command}/{method}Prio'.format(command=command, method=method))\n        data = {\n            'hashes': result.hash.lower(),\n        }\n        ok = self._request(method='post', data=data, cookies=self.session.cookies)\n\n        if self.response.status_code == 403:\n            log.info('{name}: Unable to set torrent priority because torrent queueing'\n                     ' is disabled in {name} settings.', {'name': self.name})\n            ok = True\n\n        return ok\n\n    def _set_torrent_pause(self, result):\n        api = self.api\n        state = 'pause' if app.TORRENT_PAUSED else 'resume'\n        command = 'api/v2/torrents' if api >= (2, 0, 0) else 'command'\n        hashes_key = 'hashes' if self.api >= (1, 18, 0) else 'hash'\n        self.url = urljoin(self.host, '{command}/{state}'.format(command=command, state=state))\n        data = {\n            hashes_key: result.hash.lower(),\n        }\n        return self._request(method='post', data=data, cookies=self.session.cookies)\n\n    def remove_torrent(self, info_hash):\n        \"\"\"Remove torrent from client using given info_hash.\n\n        :param info_hash:\n        :type info_hash: string\n        :return\n        :rtype: bool\n        \"\"\"\n        data = {\n            'hashes': info_hash.lower(),\n        }\n        if self.api >= (2, 0, 0):\n            self.url = urljoin(self.host, 'api/v2/torrents/delete')\n            data['deleteFiles'] = True\n        else:\n            self.url = urljoin(self.host, 'command/deletePerm')\n\n        return self._request(method='post', data=data, cookies=self.session.cookies)\n\n\napi = QBittorrentAPI\n", "path": "medusa/clients/torrent/qbittorrent.py"}], "after_files": [{"content": "# coding=utf-8\n\n\"\"\"qBittorrent Client.\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport logging\n\nfrom medusa import app\nfrom medusa.clients.torrent.generic import GenericClient\nfrom medusa.logger.adapters.style import BraceAdapter\n\nfrom requests.auth import HTTPDigestAuth\nfrom requests.compat import urljoin\n\nlog = BraceAdapter(logging.getLogger(__name__))\nlog.logger.addHandler(logging.NullHandler())\n\n\nclass APIUnavailableError(Exception):\n    \"\"\"Raised when the API version is not available.\"\"\"\n\n\nclass QBittorrentAPI(GenericClient):\n    \"\"\"qBittorrent API class.\"\"\"\n\n    def __init__(self, host=None, username=None, password=None):\n        \"\"\"Constructor.\n\n        :param host:\n        :type host: string\n        :param username:\n        :type username: string\n        :param password:\n        :type password: string\n        \"\"\"\n        super(QBittorrentAPI, self).__init__('qBittorrent', host, username, password)\n        self.url = self.host\n        # Auth for API v1.0.0 (qBittorrent v3.1.x and older)\n        self.session.auth = HTTPDigestAuth(self.username, self.password)\n\n        self.api = None\n\n    def _get_auth(self):\n        \"\"\"Authenticate with the client using the most recent API version available for use.\"\"\"\n        try:\n            auth = self._get_auth_v2()\n            version = 2\n        except APIUnavailableError:\n            auth = self._get_auth_legacy()\n            version = 1\n\n        if not auth:\n            # Authentication failed\n            return auth\n\n        # Get API version\n        if version == 2:\n            self.url = urljoin(self.host, 'api/v2/app/webapiVersion')\n            try:\n                response = self.session.get(self.url, verify=app.TORRENT_VERIFY_CERT)\n                if not response.text:\n                    raise ValueError('Response from client is empty. [Status: {0}]'.format(response.status_code))\n                # Make sure version is using the (major, minor, release) format\n                version = tuple(map(int, response.text.split('.')))\n                # Fill up with zeros to get the correct format. e.g: (2, 3) => (2, 3, 0)\n                self.api = version + (0,) * (3 - len(version))\n            except (AttributeError, ValueError) as error:\n                log.error('{name}: Unable to get API version. Error: {error!r}',\n                          {'name': self.name, 'error': error})\n        elif version == 1:\n            try:\n                self.url = urljoin(self.host, 'version/api')\n                version = int(self.session.get(self.url, verify=app.TORRENT_VERIFY_CERT).text)\n                # Convert old API versioning to new versioning (major, minor, release)\n                self.api = (1, version % 100, 0)\n            except Exception:\n                self.api = (1, 0, 0)\n\n        return auth\n\n    def _get_auth_v2(self):\n        \"\"\"Authenticate using API v2.\"\"\"\n        self.url = urljoin(self.host, 'api/v2/auth/login')\n        data = {\n            'username': self.username,\n            'password': self.password,\n        }\n        try:\n            self.response = self.session.post(self.url, data=data, verify=app.TORRENT_VERIFY_CERT)\n        except Exception as error:\n            log.warning('{name}: Exception while trying to authenticate: {error}',\n                        {'name': self.name, 'error': error}, exc_info=1)\n            return None\n\n        if self.response.status_code == 200:\n            if self.response.text == 'Fails.':\n                log.warning('{name}: Invalid Username or Password, check your config',\n                            {'name': self.name})\n                return None\n\n            # Successful log in\n            self.session.cookies = self.response.cookies\n            self.auth = self.response.text\n\n            return self.auth\n\n        if self.response.status_code == 404:\n            # API v2 is not available\n            raise APIUnavailableError()\n\n        if self.response.status_code == 403:\n            log.warning('{name}: Your IP address has been banned after too many failed authentication attempts.'\n                        ' Restart {name} to unban.',\n                        {'name': self.name})\n            return None\n\n    def _get_auth_legacy(self):\n        \"\"\"Authenticate using legacy API.\"\"\"\n        self.url = urljoin(self.host, 'login')\n        data = {\n            'username': self.username,\n            'password': self.password,\n        }\n        try:\n            self.response = self.session.post(self.url, data=data, verify=app.TORRENT_VERIFY_CERT)\n        except Exception as error:\n            log.warning('{name}: Exception while trying to authenticate: {error}',\n                        {'name': self.name, 'error': error}, exc_info=1)\n            return None\n\n        # API v1.0.0 (qBittorrent v3.1.x and older)\n        if self.response.status_code == 404:\n            try:\n                self.response = self.session.get(self.host, verify=app.TORRENT_VERIFY_CERT)\n            except Exception as error:\n                log.warning('{name}: Exception while trying to authenticate: {error}',\n                            {'name': self.name, 'error': error}, exc_info=1)\n                return None\n\n        self.session.cookies = self.response.cookies\n        self.auth = (self.response.status_code != 404) or None\n\n        return self.auth\n\n    def _add_torrent_uri(self, result):\n\n        command = 'api/v2/torrents/add' if self.api >= (2, 0, 0) else 'command/download'\n        self.url = urljoin(self.host, command)\n        data = {\n            'urls': result.url,\n        }\n        return self._request(method='post', data=data, cookies=self.session.cookies)\n\n    def _add_torrent_file(self, result):\n\n        command = 'api/v2/torrents/add' if self.api >= (2, 0, 0) else 'command/upload'\n        self.url = urljoin(self.host, command)\n        files = {\n            'torrents': result.content\n        }\n        return self._request(method='post', files=files, cookies=self.session.cookies)\n\n    def _set_torrent_label(self, result):\n\n        label = app.TORRENT_LABEL_ANIME if result.series.is_anime else app.TORRENT_LABEL\n        if not label:\n            return True\n\n        api = self.api\n        if api >= (2, 0, 0):\n            self.url = urljoin(self.host, 'api/v2/torrents/setCategory')\n            label_key = 'category'\n        elif api > (1, 6, 0):\n            label_key = 'Category' if api >= (1, 10, 0) else 'Label'\n            self.url = urljoin(self.host, 'command/set' + label_key)\n\n        data = {\n            'hashes': result.hash.lower(),\n            label_key.lower(): label.replace(' ', '_'),\n        }\n        ok = self._request(method='post', data=data, cookies=self.session.cookies)\n\n        if self.response.status_code == 409:\n            log.warning('{name}: Unable to set torrent label. You need to create the label '\n                        ' in {name} first.', {'name': self.name})\n            ok = True\n\n        return ok\n\n    def _set_torrent_priority(self, result):\n\n        command = 'api/v2/torrents' if self.api >= (2, 0, 0) else 'command'\n        method = 'increase' if result.priority == 1 else 'decrease'\n        self.url = urljoin(self.host, '{command}/{method}Prio'.format(command=command, method=method))\n        data = {\n            'hashes': result.hash.lower(),\n        }\n        ok = self._request(method='post', data=data, cookies=self.session.cookies)\n\n        if self.response.status_code == (409 if self.api >= (2, 0, 0) else 403):\n            log.info('{name}: Unable to set torrent priority because torrent queueing'\n                     ' is disabled in {name} settings.', {'name': self.name})\n            ok = True\n\n        return ok\n\n    def _set_torrent_pause(self, result):\n        api = self.api\n        state = 'pause' if app.TORRENT_PAUSED else 'resume'\n        command = 'api/v2/torrents' if api >= (2, 0, 0) else 'command'\n        hashes_key = 'hashes' if self.api >= (1, 18, 0) else 'hash'\n        self.url = urljoin(self.host, '{command}/{state}'.format(command=command, state=state))\n        data = {\n            hashes_key: result.hash.lower(),\n        }\n        return self._request(method='post', data=data, cookies=self.session.cookies)\n\n    def remove_torrent(self, info_hash):\n        \"\"\"Remove torrent from client using given info_hash.\n\n        :param info_hash:\n        :type info_hash: string\n        :return\n        :rtype: bool\n        \"\"\"\n        data = {\n            'hashes': info_hash.lower(),\n        }\n        if self.api >= (2, 0, 0):\n            self.url = urljoin(self.host, 'api/v2/torrents/delete')\n            data['deleteFiles'] = True\n        else:\n            self.url = urljoin(self.host, 'command/deletePerm')\n\n        return self._request(method='post', data=data, cookies=self.session.cookies)\n\n\napi = QBittorrentAPI\n", "path": "medusa/clients/torrent/qbittorrent.py"}]}