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 Saving JPEG Raises Error #3979
Labels
Milestone
Comments
|
Other filetype problems: PGF: ERROR:tornado.application:Uncaught exception GET /1/download.pgf (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8988', method='GET', uri='/1/download.pgf', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://127.0.0.1:8988/', 'Host': '127.0.0.1:8988', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0'})
Traceback (most recent call last):
File "/home/afrl/anaconda/lib/python2.7/site-packages/tornado/web.py", line 1332, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_webagg.py", line 201, in get
manager.canvas.print_figure(buff, format=fmt)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 2216, in print_figure
**kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 838, in print_pgf
if not os.path.exists(fname_or_fh.name):
AttributeError: '_io.BytesIO' object has no attribute 'name' TIF (similar to JPEG problem): ERROR:tornado.application:Uncaught exception GET /1/download.tif (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8988', method='GET', uri='/1/download.tif', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://127.0.0.1:8988/', 'Host': '127.0.0.1:8988', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0'})
Traceback (most recent call last):
File "/home/afrl/anaconda/lib/python2.7/site-packages/tornado/web.py", line 1332, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_webagg.py", line 201, in get
manager.canvas.print_figure(buff, format=fmt)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 2216, in print_figure
**kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_agg.py", line 592, in print_tif
dpi=dpi)
File "/home/afrl/anaconda/lib/python2.7/site-packages/PIL/Image.py", line 1439, in save
save_handler(self, fp, filename)
File "/home/afrl/anaconda/lib/python2.7/site-packages/PIL/TiffImagePlugin.py", line 841, in _save
("raw", (0,0)+im.size, offset, (rawmode, stride, 1))
File "/home/afrl/anaconda/lib/python2.7/site-packages/PIL/ImageFile.py", line 476, in _save
fh = fp.fileno()
UnsupportedOperation: fileno
ERROR:tornado.access:500 GET /1/download.tif (127.0.0.1) 39.17ms |
The following fixes the diff --git a/lib/matplotlib/backends/backend_webagg.py b/lib/matplotlib/backends/backend_webagg.py
index 9583906..16ef87b 100644
--- a/lib/matplotlib/backends/backend_webagg.py
+++ b/lib/matplotlib/backends/backend_webagg.py
@@ -197,7 +197,13 @@ class WebAggApplication(tornado.web.Application):
self.set_header('Content-Type', mimetypes.get(fmt, 'binary'))
- buff = io.BytesIO()
+ # override fileno to raise AttributeError so PIL doesn't error
+ class BytesIO(io.BytesIO):
+ @property
+ def fileno(self):
+ raise AttributeError
+
+ buff = BytesIO()
manager.canvas.print_figure(buff, format=fmt)
self.write(buff.getvalue()) |
I tried working around the ERROR:tornado.application:Uncaught exception GET /1/download.pgf (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8988', method='GET', uri='/1/download.pgf', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Connection': 'keep-alive', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://127.0.0.1:8988/', 'Host': '127.0.0.1:8988', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0'})
Traceback (most recent call last):
File "/home/afrl/anaconda/lib/python2.7/site-packages/tornado/web.py", line 1332, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_webagg.py", line 207, in get
manager.canvas.print_figure(buff, format=fmt)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backend_bases.py", line 2216, in print_figure
**kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 843, in print_pgf
self._print_pgf_to_fh(fname_or_fh, *args, **kwargs)
File "/home/afrl/workspace/matplotlib/lib/matplotlib/backends/backend_pgf.py", line 805, in _print_pgf_to_fh
fh.write(header_text)
TypeError: 'unicode' does not have the buffer interface |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To reproduce, run the following script (in master, on Python 2.7):
It looks like
PIL
is looking for afileno
attribute on the object but theio.BytesIO
obj passed bybackend_webagg
has nofileno
.The text was updated successfully, but these errors were encountered: