Serving a Single File from the Root

27 views
Skip to first unread message

Sydo Luciani

unread,
Mar 14, 2020, 3:34:14 PM3/14/20
to pylons-discuss
Procedure to serve favicon.ico from root:

Throws error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 34: invalid start byte

Apparently open().read() can't decode favicon.ico.

Has any one had success with this procedure ?

I had to change the favicon_view to return "FileResponse" object to make it work:

somehow the .rst file on github not showing the code that shows in .html or in .raw file:


Michael Merickel

unread,
Mar 14, 2020, 3:50:35 PM3/14/20
to pylons-...@googlegroups.com
The unicode issue is just due to opening the file in unicode mode (the default in python 3) and then setting the result to body (which expects bytes). Modify the open calls to use open(..., 'rb') and it should work.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/6aab8e65-007a-48e4-b400-41af3fa26623%40googlegroups.com.

Sydo Luciani

unread,
Mar 14, 2020, 4:30:23 PM3/14/20
to pylons-...@googlegroups.com
Adding 'rb' parameter to open method fixed the issue.

Thank you

Reply all
Reply to author
Forward
0 new messages