Skip to content

Commit 73a27db

Browse files
Eijebongtomrittervg
authored andcommitted
Use requests' json argument when passing JSON to the taskcluster API
When triggering hooks, the previous code was serializing the JSON itself then passing it straight to taskcluster as a string with no content type. This currently works because the taskcluster proxy has a workaround (see taskcluster/taskcluster#3521) that sets the content type to application/json if it's missing from a request with a non empty body. This means that if that workaround was ever removed or if this script tries to target taskcluster directly without the proxy, the request would fail. Just use `requests.post(json=` and get serialization and the header for free. The manual json.dumps() and the \n to space replace were leftovers from when the payload was shelled out through `echo -n '...' | taskcluster-darwin-amd64` in the past, where embedded newlines broke the quoted shell string.
1 parent 479a4a2 commit 73a27db

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

apis/taskcluster.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

77
from enum import unique, IntEnum
8-
import json
98
import jsone
109
import platform
1110
import requests
@@ -442,13 +441,12 @@ def retrigger_jobs(self, retrigger_list):
442441
template = retrigger_action['hookPayload']
443442

444443
payload = jsone.render(template, context)
445-
payload = json.dumps(payload).replace("\\n", " ")
446444

447445
trigger_url = self.url_taskcluster + "api/hooks/v1/hooks/%s/%s/trigger" % \
448446
(quote_plus(retrigger_action["hookGroupId"]), quote_plus(retrigger_action["hookId"]))
449447

450448
self.logger.log("Issuing a retrigger to %s" % (trigger_url), level=LogLevel.Info)
451-
r = requests.post(trigger_url, data=payload)
449+
r = requests.post(trigger_url, json=payload)
452450
try:
453451
if r.status_code == 200:
454452
output = r.json()

0 commit comments

Comments
 (0)