On Wed, Aug 30, 2017 at 5:09 PM, Tim Ward <[email protected]> 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 <[email protected]> (大前 潤)
--
You received this message because you are subscribed to the Google Groups "Trac
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/d/optout.