Open Mark-Hetherington opened 5 years ago
FYI: I ran into this issue as well, and was able to work around it by bypassing the subclass's Response.write
method and called directly into the base class's write
method.
The error happens here:
https://github.com/GoogleCloudPlatform/webapp2/blob/master/webapp2.py#L420
It occurs when trying to pass bytes
content (e.g. a binary asset like a JPG file) as the text
parameter.
I worked around it by replacing the self.response.out.write(...)
code in my handler with the following, where I bypass the subclass's write
method and just call into the webob.Response.write
directly.
fp = open(path, 'rb') # Path is the path to the binary file I'm trying to send.
super(webapp2.Response, self.response).write(fp.read())
FYI: This seems to work for me, but I'm not sure if there are any side effects that may crop up from this approach.
I'm trying to stream a file to the web browser, and to do this I'm using handler.request.write(bytes). However webapp tries to convert the bytes to text, which fails as the bytes are not valid for any character set: