Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAgg favicon serving error in Python 3 #2265

Merged
merged 1 commit into from Aug 1, 2013

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Aug 1, 2013

backend_webagg.py, near line 381:

class FavIcon(tornado.web.RequestHandler):
        def get(self):
            self.set_header('Content-Type', 'image/png')
            with open(os.path.join(WebAggApplication._mpl_dirs['images'],
                                   'matplotlib.png')) as fd:
                self.write(fd.read())

Doing self.write(fd.read()) is an error: Tornado converts everything passed into write() to utf-8 at least in Python 3, so that I get the following runtime error after opening a web browser:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/tornado/web.py", line 1042, in _execute
getattr(self, self.request.method.lower())(_args, *_kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_webagg.py", line 381, in get
self.write(fd.read())
File "/usr/lib/python3.3/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

This error is reasonable: trying to convert binary data - matplotlib.png - to utf8 is definitely a bad idea. I am not sure how to fix it, as I am novice to Tornado and Python in general.

@pelson
Copy link
Member

pelson commented Aug 1, 2013

Thanks for reporting @vmarkovtsev. I'm sure we can get this fixed up in pretty short order.

@ghost ghost assigned mdboom Aug 1, 2013
@mdboom
Copy link
Member

mdboom commented Aug 1, 2013

I'm working on a fix now...

@mdboom
Copy link
Member

mdboom commented Aug 1, 2013

A fix is attached. Note that to reproduce, you may need to hit the "refresh" button in your browser to get it to re-fetch the favicon.

pelson added a commit that referenced this pull request Aug 1, 2013
WebAgg favicon serving error in Python 3
@pelson pelson merged commit 2766df0 into matplotlib:v1.3.x Aug 1, 2013
@mdboom mdboom deleted the webagg-python3-encoding-issues branch August 7, 2014 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants