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