{"action":"opened","issue":{"url":"https://api.github.com/repos/mher/flower/issues/437","labels_url":"https://api.github.com/repos/mher/flower/issues/437/labels{/name}","comments_url":"https://api.github.com/repos/mher/flower/issues/437/comments","events_url":"https://api.github.com/repos/mher/flower/issues/437/events","html_url":"https://github.com/mher/flower/issues/437","id":97699677,"number":437,"title":"Non utf-8 results exception","user":{"login":"xBeAsTx","id":3618442,"avatar_url":"https://avatars.githubusercontent.com/u/3618442?v=3","gravatar_id":"","url":"https://api.github.com/users/xBeAsTx","html_url":"https://github.com/xBeAsTx","followers_url":"https://api.github.com/users/xBeAsTx/followers","following_url":"https://api.github.com/users/xBeAsTx/following{/other_user}","gists_url":"https://api.github.com/users/xBeAsTx/gists{/gist_id}","starred_url":"https://api.github.com/users/xBeAsTx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xBeAsTx/subscriptions","organizations_url":"https://api.github.com/users/xBeAsTx/orgs","repos_url":"https://api.github.com/users/xBeAsTx/repos","events_url":"https://api.github.com/users/xBeAsTx/events{/privacy}","received_events_url":"https://api.github.com/users/xBeAsTx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-28T12:54:51Z","updated_at":"2015-07-28T12:54:51Z","closed_at":null,"body":"If in results object we have some non utf-8 characters we get this exception:\r\n```\r\n[E 150728 15:51:29 web:1421] Uncaught exception GET /api/task/result/f0209a45-1b09-42b7-a284-5d4d5082b10a (127.0.0.1)\r\n    HTTPServerRequest(protocol='http', host='127.0.0.1:5555', method='GET', uri='/api/task/result/f0209a45-1b09-42b7-a284-5d4d5082b10a', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Host': '127.0.0.1:5555', 'Accept': '*/*', 'User-Agent': 'curl/7.38.0'})\r\n    Traceback (most recent call last):\r\n      File \"<env>\\lib\\site-packages\\tornado\\web.py\", line 1346, in _execute\r\n        result = method(*self.path_args, **self.path_kwargs)\r\n      File \"<env>\\lib\\site-packages\\tornado\\web.py\", line 2626, in wrapper\r\n        return method(self, *args, **kwargs)\r\n      File \"<src>\\flower\\flower\\api\\tasks.py\", line 314, in get\r\n        self.update_response_result(response, result)\r\n      File \"<src>\\flower\\flower\\api\\tasks.py\", line 51, in update_response_result\r\n        response.update({'result': self.safe_result(result.result)})\r\n      File \"<src>\\flower\\flower\\api\\tasks.py\", line 72, in safe_result\r\n        json.dumps(result)\r\n      File \"C:\\Python27\\Lib\\json\\__init__.py\", line 243, in dumps\r\n        return _default_encoder.encode(obj)\r\n      File \"C:\\Python27\\Lib\\json\\encoder.py\", line 207, in encode\r\n        chunks = self.iterencode(o, _one_shot=True)\r\n      File \"C:\\Python27\\Lib\\json\\encoder.py\", line 270, in iterencode\r\n        return _iterencode(o, 0)\r\n    UnicodeDecodeError: 'utf8' codec can't decode byte 0xfc in position 52: invalid start byte\r\n```\r\n\r\nMy fix would be:\r\n```python\r\ndef safe_result(self, result):\r\n        \"returns json encodable result\"\r\n        try:\r\n            json.dumps(result)\r\n        except TypeError:\r\n            return repr(result)\r\n        except UnicodeDecodeError:\r\n            result_reencoded = unicode(json.dumps(result, ensure_ascii=False), errors='replace').encode(\"ascii\", \"replace\")\r\n            return json.loads(result_reencoded)\r\n        else:\r\n            return result\r\n```"}}