Handle UnicodeEncodeErrors from junk URLs.

This commit is contained in:
Ben Sturmfels 2022-03-15 10:58:32 +11:00
parent 90e75a3007
commit 6b1ed75d7a
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0

View file

@ -34,7 +34,12 @@ def index(request, *args, **kwargs):
if path.endswith(u'/'):
path += u'index.html'
fullpath = os.path.join(STATIC_ROOT, path)
if not os.path.exists(fullpath):
try:
# Junk URLs in production (Python 3.5) are causing UnicodeEncodeErrors
# here. Can't reproduce in development in Python 3.9 - only Python 2.7.
if not os.path.exists(fullpath):
return handler404(request)
except UnicodeEncodeError:
return handler404(request)
content_type, _ = mimetypes.guess_type(path)
if content_type != 'text/html':