On Wed, Aug 30, 2017 at 5:09 PM, Tim Ward <
t...@brettward.co.uk> wrote:
> data = '{{ "params": [ {}, "{}", {{ "action": "leave" }}, true ],
> "method": "ticket.update" }}'
>
> r =
requests.post( url, data=data.format( ticketId, comment ),
> headers=headers, auth=auth )
>
> (Python) - how do I usefully include a line break in the content of the
> comment string variable?
Your generated json string is incorrect. Your request with the
incorrect json leads error response from XMLRPC plugin.
>>> data = '{{ "params": [ {}, "{}", {{ "action": "leave" }}, true ], "method": "ticket.update" }}'
>> print(data.format(42, 'line 1\nline 2\n'))
{ "params": [ 42, "line 1
line 2
", { "action": "leave" }, true ], "method": "ticket.update" }
You should use json.dumps() rather than directly generating json
string if you cannot implement it.
>>> import json
>>> ticketId = 42
>>> comment = 'line 1\nline 2\n'
>>> data = {'params': [ticketId, comment, {'action': 'leave'}, True], 'method': 'ticket.update'}
>>> print(json.dumps(data))
{"params": [42, "line 1\nline 2\n", {"action": "leave"}, true],
"method": "ticket.update"}
--
Jun Omae <
jun...@gmail.com> (大前 潤)