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

Links to local pdf don't work properly #179

Closed
pikaren opened this issue Jun 20, 2016 · 1 comment
Closed

Links to local pdf don't work properly #179

pikaren opened this issue Jun 20, 2016 · 1 comment
Labels

Comments

@pikaren
Copy link

pikaren commented Jun 20, 2016

When I try to access a local pdf via the link [link to local pdf](local.pdf), the server returns the error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 10: invalid continuation byte
127.0.0.1 - - [20/Jun/2016 17:57:47] "GET /local.pdf HTTP/1.1" 500 -
[2016-06-20 17:58:44,374] ERROR in app: Exception on /local.pdf [GET]
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functionsrule.endpoint
File "/usr/lib/python3.5/site-packages/grip/app.py", line 163, in _render_page
text = self.reader.read(subpath)
File "/usr/lib/python3.5/site-packages/grip/readers.py", line 265, in read
return self._read_text(filename)
File "/usr/lib/python3.5/site-packages/grip/readers.py", line 146, in _read_text
return f.read()
File "/usr/lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)

Meanwhile, it serves local images properly. Is there any chance this could be fixed?

Thank you.

@joeyespo
Copy link
Owner

Hmm, this does seem like a problem / a bug.

At the moment, binary file detection is rather incomplete, so there's an opportunity for improvement. I wonder if something like this answer would be more appropriate for detecting binary files (and therefore, not trying to decode utf-8). I'll have to think more about it.

In the meantime, you could tweak that line locally in grip/grip/readers.py until an official more-general fix is released:

def is_binary(self, subpath=None):
    """
    Gets whether the specified subpath is a supported binary file.
    """
    if subpath and subpath.endswith('.pdf'):    # <-- added
        return True                             # <-- added
    mimetype = self.mimetype_for(subpath)
    return mimetype is not None and mimetype.startswith('image/')

Hope that helps. Thanks for the issue, @pikaren!

@joeyespo joeyespo added the bug label Aug 13, 2016
wvspee-eyeo added a commit to wvspee-eyeo/grip that referenced this issue Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants