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

Convert result to str before regex #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dripline/implementations/entity_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ def on_get(self):
result = self.service.send_to_device([self._get_str])
logger.debug(f'result is: {result}')
if self._extract_raw_regex is not None:
first_result = result
try:
first_result = str(result)
except:
logger.error('Failed to convert {} to string'.format(result))
raise ThrowReply('resource_error', 'Failed to convert [{}] to string'.format(result))
matches = re.search(self._extract_raw_regex, first_result)
if matches is None:
logger.error('matching returned none')
logger.error('matching [{}] with regex [{}] returned none'.format(first_result, self._extract_raw_regex))
# exceptions.DriplineValueError
raise ThrowReply('resource_error', 'device returned unparsable result, [{}] has no match to input regex [{}]'.format(first_result, self._extract_raw_regex))
logger.debug(f"matches are: {matches.groupdict()}")
Expand Down