Skip to content

Commit

Permalink
Show CiscoIPPhoneError messages for non-200 responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-palmer committed Apr 6, 2022
1 parent 67a751f commit a60a8a5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ persistent=no
extension-pkg-whitelist=lxml

[MESSAGES CONTROL]
disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,bad-whitespace,invalid-name,redefined-builtin,broad-except,consider-using-sys-exit,too-many-branches,too-many-statements,too-many-arguments,line-too-long,too-many-locals,len-as-condition,wrong-import-position,unused-argument,duplicate-code,too-many-nested-blocks,arguments-differ
disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,bad-whitespace,invalid-name,redefined-builtin,broad-except,multiple-statements,consider-using-sys-exit,too-many-branches,too-many-statements,too-many-arguments,line-too-long,too-many-locals,len-as-condition,wrong-import-position,unused-argument,duplicate-code,too-many-nested-blocks,arguments-differ

[REPORTS]
output-format=text
5 changes: 2 additions & 3 deletions cgiexecute
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def cgi_execute(hostname, port, timeout, username, password, certificate_file, u

response = session.post(f'{scheme}://{hostname}:{port}/CGI/Execute',
timeout = timeout, auth = auth, verify = certificate_file, data = {'XML': xml})
response.raise_for_status()

except requests.RequestException as error:
raise ProgramError(error)
Expand All @@ -71,9 +70,9 @@ def cgi_execute(hostname, port, timeout, username, password, certificate_file, u
raise ProgramError(error)

if document.tag == 'CiscoIPPhoneError':
number = document.get('Number')
number = document.get('Number', '')

raise ProgramError('Error: ' + cgi_errors.get(number, f'{number}'))
raise ProgramError('Error: ' + cgi_errors.get(number, number))

for element in document.findall('ResponseItem'):
url = element.get('URL')
Expand Down
29 changes: 23 additions & 6 deletions mediastream
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ from lxml import etree
import requests
import requests.auth
import requests.adapters
import gi
gi.require_version('Gst', '1.0')
import gi; gi.require_version('Gst', '1.0')
from gi.repository import GLib, Gst


cgi_errors = {
'1': 'Error parsing CiscoIPPhone object',
'2': 'Error framing CiscoIPPhone object',
'3': 'Internal file error',
'4': 'Authentication error'
}


class ProgramError(Exception):
pass

Expand Down Expand Up @@ -91,8 +98,16 @@ def start_media(target_hostnames, multicast_address, port, timeout, username, pa
try:
document = etree.fromstring(future.result())

if document.tag == 'CiscoIPPhoneError':
number = document.get('Number', '')

raise ProgramError('Error: ' + cgi_errors.get(number, number))

if document.tag == 'errorResponse':
raise ProgramError(document.findtext('type', '') + ': ' + document.findtext('data', ''))
type = document.findtext('type', '')
data = document.findtext('data', '')

raise ProgramError(f'Error {type}: {data}')

if document.tag != 'mediaStream':
raise ProgramError(f'Unexpected XML: {document.tag}')
Expand All @@ -101,7 +116,7 @@ def start_media(target_hostnames, multicast_address, port, timeout, username, pa
# Remove address so we don't try and send it audio
target_hostnames.remove(target_hostname)

print(f'Error {target_hostname}: {error}')
print(f'{target_hostname} {error}')


def stream_media(target_hostnames, multicast_address, port, codec, wav_file):
Expand Down Expand Up @@ -259,10 +274,12 @@ def stop_media(target_hostnames, timeout, username, password, certificate_file):
document = etree.fromstring(future.result())

if document.tag == 'CiscoIPPhoneError':
raise ProgramError(document.get('Number', '0'))
number = document.get('Number', '')

raise ProgramError('Error: ' + cgi_errors.get(number, number))

except Exception as error:
print(f'Error {target_hostname}: {error}')
print(f'{target_hostname} {error}')


def main():
Expand Down
1 change: 0 additions & 1 deletion screenshot
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def get_screenshot(hostname, port, timeout, username, password, certificate_file

response = session.get(f'{scheme}://{hostname}:{port}/CGI/Screenshot',
timeout = timeout, auth = auth, verify = certificate_file)
response.raise_for_status()

except requests.RequestException as error:
raise ProgramError(error)
Expand Down
1 change: 0 additions & 1 deletion setbackground
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def set_background(hostname, port, timeout, username, password, certificate_file

response = session.post(f'{scheme}://{hostname}:{port}/CGI/Execute',
timeout = timeout, auth = auth, verify = certificate_file, data = {'XML': xml})
response.raise_for_status()

except requests.RequestException as error:
raise ProgramError(error)
Expand Down
1 change: 0 additions & 1 deletion setringtone
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def set_ringtone(hostname, port, timeout, username, password, certificate_file,

response = session.post(f'{scheme}://{hostname}:{port}/CGI/Execute',
timeout = timeout, auth = auth, verify = certificate_file, data = {'XML': xml})
response.raise_for_status()

except requests.RequestException as error:
raise ProgramError(error)
Expand Down
1 change: 0 additions & 1 deletion xmlinfo
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def get_info(hostname, port, timeout, info, username, password, certificate_file

response = session.get(f'{scheme}://{hostname}:{port}/CGI/{path}',
timeout = timeout, auth = auth, verify = certificate_file)
response.raise_for_status()

except requests.RequestException as error:
raise ProgramError(error)
Expand Down

0 comments on commit a60a8a5

Please sign in to comment.