diff --git a/examples/frameworks/django/testing/testing/apps/someapp/views.py b/examples/frameworks/django/testing/testing/apps/someapp/views.py index d685b5bc..714abaaf 100755 --- a/examples/frameworks/django/testing/testing/apps/someapp/views.py +++ b/examples/frameworks/django/testing/testing/apps/someapp/views.py @@ -1,6 +1,7 @@ # Create your views here. import csv +import io import os from django import forms from django.http import HttpResponse @@ -28,10 +29,15 @@ def home(request): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] f = request.FILES['f'] + + if not hasattr(f, "fileno"): size = len(f.read()) else: - size = int(os.fstat(f.fileno())[6]) + try: + size = int(os.fstat(f.fileno())[6]) + except io.UnsupportedOperation: + size = len(f.read()) else: form = MsgForm() diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index 5ea54f28..a32c2573 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -275,7 +275,7 @@ class Response(object): self.send_headers() if isinstance(arg, text_type): - arg = arg.decode('utf-8') + arg = arg.encode('utf-8') assert isinstance(arg, binary_type), "%r is not a byte." % arg diff --git a/gunicorn/util.py b/gunicorn/util.py index 142f6e10..f367d2e3 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -225,9 +225,9 @@ except ImportError: def write_chunk(sock, data): if isinstance(data, text_type): - data = data.decode('utf-8') + data = data.encode('utf-8') chunk_size = "%X\r\n" % len(data) - chunk = b"".join([chunk_size.decode('utf-8'), data, b"\r\n"]) + chunk = b"".join([chunk_size.encode('utf-8'), data, b"\r\n"]) sock.sendall(chunk) def write(sock, data, chunked=False):