Handle UnicodeEncodeErrors from junk URLs.
This commit is contained in:
parent
90e75a3007
commit
6b1ed75d7a
1 changed files with 6 additions and 1 deletions
|
@ -34,8 +34,13 @@ def index(request, *args, **kwargs):
|
|||
if path.endswith(u'/'):
|
||||
path += u'index.html'
|
||||
fullpath = os.path.join(STATIC_ROOT, path)
|
||||
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':
|
||||
return HttpResponse(open(fullpath, 'rb'), content_type)
|
||||
|
|
Loading…
Reference in a new issue