get_bytes_from_wsgi Encoding

Hi guys, I’m using django and the openlitespeed wsgi Server App.
The “get_bytes_from_wsgi” method encodes the path to ‘iso-8859-1’, but I want it to encode ‘utf-8’.
because when I use non-English letters in the path of files, I get an error of 500
what’s the solution?

I don’t know of a more “proper” solution, but if I were to make a guess at something that should work, I’d look at using a custom version of get_bytes_from_wsgi.

You could probably either “monkey-patch” django.core.handlers.wsgi with your version, or you could copy that entire file into your project, and replace the call to get_wsgi_application with your own function that imports WSGIHandler from your project’s copied

No idea whether or not this will work - but if I were facing this situation, that’s what I’d be trying.

1 Like

I’m no expert on all the URL pieces, but have you researched why Django uses that encoding? What’s the exception you’re seeing?

I created a test file with a URL using Ogham characters - a rare Irish alphabet (video) and it worked fine:

import html
import os
import sys

from django.conf import settings
from django.http import HttpResponse
from django.urls import path

    DEBUG=(os.environ.get("DEBUG", "") == "1"),
    # Dangerous: disable host header validation
    # Make this module the urlconf
    # We aren't using any security features but Django requires this setting

def view(request):
    return HttpResponse("Hello!")

urlpatterns = [
    path("᚛ᚈᚑᚋ ᚄᚉᚑᚈᚈ᚜-and-᚛ᚑᚌᚐᚋ᚜/", view),

if __name__ == "__main__":
    from import execute_from_command_line

(Ran with python runserver - template)

If I were to suspect anything in your stack, it would be this. This seems like a new webserver to me, it may not conform with the WSGI spec entirely. I normally use gunicorn with nginx.

Thank you, I did exactly the same thing and copied the following file :


and i put it in the main directory of the project and customized it.
Finally, in “wsgi” file, I imported the customized file and everything works fine!

I didn’t encounter this problem when using nginx, but you do encounter this problem when you use OLS.
The OLS performance is better than the nginx, and I needed that in this project, and because of the multilingual nature of the project, which was for scientific data, I had trouble url in some languages, such as persian.
Finally, I think it’s best to create a new customized wsgi file :wink:

I’d be careful trusting any performance benchmarks they might be using to back up such a claim. They might be optimized on only one small part of the problem rather than others.

I wouldn’t exactly call it “new”. The commercial version has been around for 15+ years and the first open source version I can find on github goes back to 2013. While it may not conform exactly with the WSGI spec, they’re not exactly the new kid on the block, either.

Apart from benchmarks that show OLS performance and response speed much higher, I also easily notice the high speed of OLS as well as its amazing cache system in various projects when the number of users increases!
of course, the website you introduced was very interesting, thank you