Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set default timeouts for remaining requests calls #925

Merged
merged 2 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions soco/music_services/accounts.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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,
)