Skip to content

Commit

Permalink
Explicitly set default timeouts for remaining requests calls (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlawren authored and pwt committed Oct 22, 2022
1 parent 2261691 commit 7586a8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions soco/music_services/accounts.py
Expand Up @@ -9,7 +9,7 @@

import requests

from .. import discovery
from .. import config, discovery
from ..xml import XML

log = logging.getLogger(__name__) # pylint: disable=C0103
Expand Down Expand Up @@ -75,9 +75,7 @@ def _get_account_xml(soco):
device = soco or discovery.any_soco()
log.debug("Fetching account data from %s", device)
settings_url = "http://{}:1400/status/accounts".format(device.ip_address)
# Remove this as part of PR #925
# pylint: disable=W3101
result = requests.get(settings_url).content
result = requests.get(settings_url, timeout=config.REQUEST_TIMEOUT).content
log.debug("Account data: %s", result)
return result

Expand Down
6 changes: 4 additions & 2 deletions soco/soap.py
Expand Up @@ -32,6 +32,7 @@

import requests

from . import config
from .exceptions import SoCoException
from .utils import prettify
from .xml import XML
Expand Down Expand Up @@ -287,12 +288,13 @@ def call(self):
if _LOG.isEnabledFor(logging.DEBUG):
_LOG.debug("Sending %s, %s", headers, prettify(data))

# Remove this as part of PR #925
# pylint: disable=W3101
timeout = self.request_args.pop("timeout", config.REQUEST_TIMEOUT)

response = requests.post(
self.endpoint,
headers=headers,
data=data.encode("utf-8"),
timeout=timeout,
**self.request_args
)
_LOG.debug("Received %s, %s", response.headers, response.text)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_soap.py
@@ -1,6 +1,7 @@
"""Tests for the soap module."""


from soco.config import REQUEST_TIMEOUT
from soco.soap import SoapMessage
from soco.xml import XML
from unittest import mock
Expand Down Expand Up @@ -142,6 +143,7 @@ def test_call():
"Content-Type": 'text/xml; charset="utf-8"',
"user-agent": "sonos",
},
timeout=REQUEST_TIMEOUT,
data=mock.ANY,
other_arg=4,
)

0 comments on commit 7586a8e

Please sign in to comment.