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 wsgi.py.

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

settings.configure(
    DEBUG=(os.environ.get("DEBUG", "") == "1"),
    # Dangerous: disable host header validation
    ALLOWED_HOSTS=["*"],
    # Make this module the urlconf
    ROOT_URLCONF=__name__,
    # We aren't using any security features but Django requires this setting
    SECRET_KEY="hch@!oursic96$lyiuj=&+-9y&6pp_df$3k1#j_ub+9sy-rs5y",
)


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


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

if __name__ == "__main__":
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

(Ran with python app.py 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 :

/usr/local/lib/python3.8/dist-packages/django/core/handlers/wsgi.py

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.

http://matthewrocklin.com/blog/work/2017/03/09/biased-benchmarks

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