Repository: Miserlou/Zappa

Issue:
Response is not JSON serializable w/ Python 3.6, Flask, CORS=true, binary_support=false
## Steps to Reproduce
1. Setup a python 3.6 virtual env & activate
2. pip install flask zappa
3. Create main.py like this:

```
import json
from flask import Flask, Response
app = Flask(__name__)

@app.route('/jsonobj')
def json_only_obj():
    obj = { 'hello': 'world' }
    return json.dumps(obj), 200

if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5001)

```
4. zappa_settings.json: 
```
{
    "dev": {
        "apigateway_enabled": true,
        "apigateway_description": "hello world",
        "app_function": "main.app",
        "aws_region": "us-west-2",
        "iam_authorization": false,
        "lambda_description": "hello world", 
        "project_name": "MYPROJECT",
        "s3_bucket": "MYBUCKET",
        "timeout_seconds": 30, 
        "cors": true,
        "binary_support": false
    }
}
```
5. zappa deploy dev
6. Load: <api-gateway-url>/jsonobj

## Expected Behavior
The json object defined in json_only_obj() should be returned

## Actual Behavior
`{"message": "Internal server error"}`

Cloud watch shows:
```
An error occurred during JSON serialization of response: b'
{
    "hello": "world"
}
' is not JSON serializable
Traceback (most recent call last):
File "/var/lang/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/var/lang/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/var/lang/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/var/runtime/awslambda/bootstrap.py", line 110, in decimal_serializer
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'
{
    "hello": "world"
}
' is not JSON serializable
```

## Your Environment
* Zappa version used: 0.42.1
* Operating System and Python version: Ubuntu 16.04, Python 3.6
* The output of `pip freeze`:
argcomplete==1.8.2
base58==0.2.4
boto3==1.4.4
botocore==1.5.40
certifi==2017.4.17
chardet==3.0.4
click==6.7
docutils==0.13.1
durationpy==0.4
Flask==0.12.2
future==0.16.0
futures==3.1.1
hjson==2.0.7
idna==2.5
itsdangerous==0.24
Jinja2==2.9.6
jmespath==0.9.3
kappa==0.6.0
lambda-packages==0.15.1
MarkupSafe==1.0
placebo==0.8.1
python-dateutil==2.6.0
python-slugify==1.2.4
PyYAML==3.12
requests==2.18.1
s3transfer==0.1.10
six==1.10.0
toml==0.9.2
tqdm==4.14.0
troposphere==1.9.4
Unidecode==0.4.20
urllib3==1.21.1
Werkzeug==0.12
wsgi-request-logger==0.4.6
zappa==0.42.1


Discussion:

Resolving patch:
diff --git a/zappa/handler.py b/zappa/handler.py
--- a/zappa/handler.py
+++ b/zappa/handler.py
@@ -445,7 +445,7 @@ def handler(self, event, context):
                         else:
                             zappa_returndict['body'] = response.data
                     else:
-                        zappa_returndict['body'] = response.data
+                        zappa_returndict['body'] = response.get_data(as_text=True)
 
                 zappa_returndict['statusCode'] = response.status_code
                 zappa_returndict['headers'] = {}


Test patch: