[chromium-try-flakes] Remove prefix ')]}\'\n' from Milo response.

TBR=nodir@chromium.org
Bug: 811333
Change-Id: I15515ec0d1e14602e1f23815c8e4a53f23be19e4
Reviewed-on: https://chromium-review.googlesource.com/927929
Reviewed-by: Shuotao Gao <stgao@chromium.org>
Commit-Queue: Shuotao Gao <stgao@chromium.org>
diff --git a/appengine/chromium_try_flakes/handlers/flake_issues.py b/appengine/chromium_try_flakes/handlers/flake_issues.py
index 7e4d869..f690205 100644
--- a/appengine/chromium_try_flakes/handlers/flake_issues.py
+++ b/appengine/chromium_try_flakes/handlers/flake_issues.py
@@ -129,6 +129,9 @@
 IGNORED_STEPS = ['steps', 'presubmit', 'recipe failure reason', 'test results',
                  'Uncaught Exception', 'Failure reason', 'analyze']
 
+# Response prefix of Milo API.
+_MILO_RESPONSE_PREFIX = ')]}\'\n'
+
 
 def is_infra_step_flake(flake_name):
   return flake_name in KNOWN_INFRA_STEPS_NAMES
@@ -758,7 +761,10 @@
                     response.status_code, response.content)
       self.response.set_status(500, 'Failed to fetch build.')
       return
-    data = json.loads(response.content)['data']
+    content = response.content
+    if content.startswith(_MILO_RESPONSE_PREFIX):
+      content = content[len(_MILO_RESPONSE_PREFIX):]
+    data = json.loads(content)['data']
     json_result = json.loads(base64.b64decode(data))
     steps = json_result['steps']
 
diff --git a/appengine/chromium_try_flakes/handlers/test/flake_issues_test.py b/appengine/chromium_try_flakes/handlers/test/flake_issues_test.py
index 5c2d363..50a4c91 100644
--- a/appengine/chromium_try_flakes/handlers/test/flake_issues_test.py
+++ b/appengine/chromium_try_flakes/handlers/test/flake_issues_test.py
@@ -63,7 +63,7 @@
 })
 
 
-TEST_BUILDBOT_JSON_REPLY = json.dumps({
+TEST_BUILDBOT_JSON_REPLY = ')]}\'\n' + json.dumps({
   'data': base64.b64encode(json.dumps({
     'steps': [
       # Simple case.