Opened 5 years ago
Closed 5 years ago
Last modified 5 years ago
#13619 closed Patch - Feature (fixed)
Python services-api enhancements
Reported by: | rcrdnalor | Owned by: | Bill Meek |
---|---|---|---|
Priority: | minor | Milestone: | 31.1 |
Component: | Bindings - Python | Version: | Master Head |
Severity: | medium | Keywords: | services-api |
Cc: | Ticket locked: | no |
Description (last modified by )
1) Python's lxml module works best if fed with raw data from a 'Request.session.get' response.
A new option provided by this patch allows returning data as raw data i.e.: returning the recieved 'response.content'. This can be easily handled by the lxml.etree.fromstring() method.
An example how to use this feature:
$ python3 >>> from MythTV.services_api import send as API >>> from lxml import etree >>> host = "localhost" >>> mythrequest = API.Send(host) >>> endpoint = "/Dvr/GetRecordedList" >>> restdata = "Descending=True&Count=3" >>> opts = {'rawxml': True} ### < --- new option >>> response = mythrequest.send(endpoint=endpoint, rest=restdata, opts=opts) >>> eroot = etree.fromstring(response) >>> print(etree.tostring(eroot, pretty_print=True, encoding='unicode'))
Verified also with python2.
Attached a patch adding this additional option.
2) The mythservices-api requires the 'post' data to be passed as dictionary. For classes derived from dictionary (dict), it is not mandatory to provide an attribute 'keys', but the methods 'keys()', 'values()', 'items()' must always be implemented.
Using the latter methods, allows logging of a 'post' operation for those classes derived from 'dict'.
Otherwise, on get a traceback showing an 'AttributeError' or a 'KeyError'. The class 'OrdDict' from the python bindings is such an example.
Attached a patch that improves logging for 'post' operations.
Attachments (2)
Change History (5)
Changed 5 years ago by
Attachment: | 01_improve_logging_of_post_operations.patch added |
---|
Changed 5 years ago by
Attachment: | 02_add_option_to_return_raw_content.patch added |
---|
Add option to return raw data
Improve logging of 'post' operations