Skip to content

Commit

Permalink
hopefully final testing for timeouts...
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Sep 30, 2021
1 parent dc84a62 commit 4421439
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 251 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ Getting Started
import qbittorrentapi

# instantiate a Client using the appropriate WebUI configuration
qbt_client = qbittorrentapi.Client(host='localhost', port=8080, username='admin', password='adminadmin')
qbt_client = qbittorrentapi.Client(
host='localhost',
port=8080,
username='admin',
password='adminadmin',
)

# the Client will automatically acquire/maintain a logged in state in line with any request.
# therefore, this is not necessary; however, you may want to test the provided login credentials.
# the Client will automatically acquire/maintain a logged-in state
# in line with any request. therefore, this is not strictly necessary;
# however, you may want to test the provided login credentials.
try:
qbt_client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
Expand Down
25 changes: 18 additions & 7 deletions docs/source/behavior&configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ Untrusted WebUI Certificate

Host, Username and Password
***************************
* These can be provided when instantiating Client or calling ``qbt_client.auth_log_in(username='...', password='...')``.
* These can be provided when instantiating ``Client`` or calling ``qbt_client.auth_log_in(username='...', password='...')``.
* Alternatively, set environment variables ``PYTHON_QBITTORRENTAPI_HOST``, ``PYTHON_QBITTORRENTAPI_USERNAME`` and ``PYTHON_QBITTORRENTAPI_PASSWORD``.

Custom HTTP Headers
***************************
* To send a custom HTTP header in all requests made from an instantiated client, declare them during instantiation.
Requests Configuration
**********************
* The `Requests <https://docs.python-requests.org/en/latest/>`_ package is used to issue HTTP requests to qBittorrent to facilitate this API.
* Much of ``Requests`` configuration for making HTTP calls can be controlled with parameters passed along with the request payload.
* For instance, HTTP Basic Authorization credentials can be provided via ``auth``, timeouts via ``timeout``, or Cookies via ``cookies``.
* These parameters are exposed here in two ways; the examples below tell ``Requests`` to use a connect timeout of 3.1 seconds and a read timeout of 30 seconds.
* When you instantiate ``Client``, you can specify the parameters to use in all HTTP requests to qBittorrent:
* ``qbt_client = Client(..., requests_args={'timeout': (3.1, 30)}``
* Alternatively, parameters can be specified for individual requests:
* ``qbt_client.torrents_info(..., requests_args={'timeout': (3.1, 30))``

Additional HTTP Headers
***********************
* For consistency, HTTP Headers can be specified using the method above; for backwards compatability, the methods below are supported as well.
* Either way, these additional headers will be incorporated (using clobbering) into the rest of the headers to be sent.
* To send a custom HTTP header in all requests made from an instantiated client, declare them during instantiation:
* ``qbt_client = Client(..., EXTRA_HEADERS={'X-My-Fav-Header': 'header value')``
* Alternatively, you can send custom headers in individual requests.
* Alternatively, you can send custom headers in individual requests:
* ``qbt_client.torrents.add(..., headers={'X-My-Fav-Header': 'header value')``
* These headers will be merged with other headers otherwise configured to be sent.

Unimplemented API Endpoints
***************************
Expand All @@ -30,7 +42,6 @@ Unimplemented API Endpoints
Disable Logging Debug Output
****************************
* Instantiate Client with `DISABLE_LOGGING_DEBUG_OUTPUT=True` or manually disable logging for the relevant packages:

* ``logging.getLogger('qbittorrentapi').setLevel(logging.INFO)``
* ``logging.getLogger('requests').setLevel(logging.INFO)``
* ``logging.getLogger('urllib3').setLevel(logging.INFO)``
2 changes: 1 addition & 1 deletion qbittorrentapi/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import getLogger
from json import dumps
from logging import getLogger

from qbittorrentapi.decorators import Alias
from qbittorrentapi.decorators import aliased
Expand Down
4 changes: 2 additions & 2 deletions qbittorrentapi/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def _SID(self):
:return: SID auth cookie from qBittorrent or None if one isn't already acquired
"""
if self._requests_session:
return self._requests_session.cookies.get("SID", None)
if self._http_session:
return self._http_session.cookies.get("SID", None)
return None

@login_required
Expand Down
7 changes: 4 additions & 3 deletions qbittorrentapi/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from qbittorrentapi.app import AppAPIMixIn
from qbittorrentapi.auth import AuthAPIMixIn
from qbittorrentapi.log import LogAPIMixIn
from qbittorrentapi.sync import SyncAPIMixIn
from qbittorrentapi.transfer import TransferAPIMixIn
from qbittorrentapi.torrents import TorrentsAPIMixIn
from qbittorrentapi.rss import RSSAPIMixIn
from qbittorrentapi.search import SearchAPIMixIn
from qbittorrentapi.sync import SyncAPIMixIn
from qbittorrentapi.torrents import TorrentsAPIMixIn
from qbittorrentapi.transfer import TransferAPIMixIn


# NOTES
# Implementation
Expand Down
7 changes: 4 additions & 3 deletions qbittorrentapi/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from logging import getLogger
from functools import wraps
from json import loads
from logging import getLogger

from pkg_resources import parse_version

from qbittorrentapi.exceptions import APIError
Expand Down Expand Up @@ -181,9 +182,9 @@ def wrapper(client, *args, **kwargs):
if simple_response:
return result
return response_class(result, client)
except Exception as e:
except Exception as exc:
logger.debug("Exception during response parsing.", exc_info=True)
raise APIError("Exception during response parsing. Error: %s" % repr(e))
raise APIError("Exception during response parsing. Error: %r" % exc)

return wrapper

Expand Down
2 changes: 1 addition & 1 deletion qbittorrentapi/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from requests.exceptions import RequestException
from requests.exceptions import HTTPError as RequestsHTTPError
from requests.exceptions import RequestException


class APIError(Exception):
Expand Down
Loading

0 comments on commit 4421439

Please sign in to comment.