Forum Discussion
So with a little help from various sources, inc. the support team, to get me past my Python inadequacies I have something basic working to pull records out of the database via the JSON APIs.
The initial problems was my duff formatting of the command and also the help of the json.dumps() function (should read this stuff before I try and use it!).
Condensed extract below of the key bits.
I can issue now successfully command posts and process responses to create 'custom' classes from them so I can add whatever methods I later want :smileyhappy:
# Headers to specify the content type and encoding for the query
headers = {'Content-Type': 'application/json;charset=utf-8'}
# val_get_version = {"command" : "ServerInfoService.getVersion"}
# json.dumps() returns $ and data must be a bytes object sto send to the server
json_val_get_version = json.dumps([
{
u'command' : (u'ServerInfoService.getVersion')
}
])
# It should be encoded to bytes (UTF-8) before being used as the data parameter.
cmd_data = json_val_get_version
cmd_data.encode('utf-8')
req = urllib.request.Request(url, cmd_data, headers=headers)
response = urllib.request.urlopen(req)
for record in response :
# convert byte object record into string?
record = record.decode('utf-8')
obj = json.loads(record, object_hook = CCollab_Participants_from_json)
# etc...
The CCollab_Version_from_json) hook traverses the record structure (if it is nested) and creates the custom CCollab_Version class object for me to do as I wish with.
I still have the hurdle of extracting JUST the Subversion revision from the ReviewSummary (I am not ware of it being available anywhere else but maybe I need to dig more).
Currently for an all but empty Review this is ~15K characters and a level of nesting (and consequently traversing) that is a little off-putting...
Related Content
- 7 months agobleahy
- 6 years agosriram_sig
- 2 years agolalit_singh
Recent Discussions
- 7 days agorturner
- 17 days agomardito
Changing role settings
Solved18 days agoChrisF1- 20 days agoOGrimm