TT#19758 Fix Python3 string representation issue with json.loads

In Python3 all strings are considered Unicode by default. The
unicode type from Python 2 is called str in Python 3, and str
becomes bytes. In Python3, there aren’t any automatic conversions
between str and bytes though. The json.loads in Python versions
>3 and <3.6 expects a string representation and not bytes. As we
receive bytes we need to decode() it, as this always returns str,
just as needed.

Fixes:

| File "./release_dashboard/views/build.py", line 59, in hotfix_build
| json_data = json.loads(request.body)
| File "/usr/lib/python3.4/json/__init__.py", line 312, in loads
| s.__class__.__name__))
| TypeError: the JSON object must be str, not 'bytes'

See https://docs.djangoproject.com/en/1.11/topics/python3/ and
https://vinta.ws/code/notes-of-porting-to-python-3-for-a-django-project.html
for related documentation.

Change-Id: I3984c5fd1f79b94680e680c8da64dd0ac111cbe9
changes/93/14693/1
Michael Prokop 8 years ago
parent 63d904d977
commit 541e5418ac

@ -56,7 +56,7 @@ def hotfix_build(request, branch, project):
logger.error(error)
return HttpResponseNotFound(error)
json_data = json.loads(request.body)
json_data = json.loads(request.body.decode('utf-8'))
if json_data['push'] == 'no':
logger.warn("dryrun for %s:%s", project, branch)
url = build.trigger_hotfix(project, branch, json_data['push'])

Loading…
Cancel
Save