Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#30303 closed Bug (duplicate)

Error handler page generating unicode decode error.

Reported by: Kevin Golding Owned by:
Component: Error reporting Version: 2.2
Severity: Normal Keywords: wsgi unicode
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Running 2.2 under wsgi generates a 500 error when the error handler page is triggered for any reason.

I basically created an empty project which just shows the rocket page. When I run with the inbuilt server and try to view this from a different computer it displays an error page (with the big yellow band across the top and all the useful information) because I haven't added anything to ALLOWED_HOSTS.

If I then configure it to run in Apache using wsgi, it just generates a 500 error and the accompanying error.log.

This works properly in django 2.1.

Attachments (1)

error.log.txt (13.9 KB) - added by Kevin Golding 3 years ago.
Apache error log

Download all attachments as: .zip

Change History (5)

Changed 3 years ago by Kevin Golding

Attachment: error.log.txt added

Apache error log

comment:1 Changed 3 years ago by Carlton Gibson

Hi Kevin,

Thanks for the report. Struggling to reproduce this, or see any plausible cause. Can you help us to reproduce please?

You're getting a UnicodeDecodeError when loading the technical_500.html template. (It's tripping up on a "â" character, but that doesn't appear...) — So how's that's coming up?
Without more info it's difficult to know what to say...

comment:2 Changed 3 years ago by Carlton Gibson

Resolution: needsinfo
Status: newclosed

This doesn't reproduce as far as we can see. I'm going to close this as needsinfo.

As I said, the error is coming up when loading the 500 error template:

        with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:
            t = DEBUG_ENGINE.from_string(

Here the question is why is the ascii encoding being used? From the `open()` docs:

The default encoding is platform dependent (whatever locale.getpreferredencoding() returns)...

This looks like an environment issue.

Very happy to re-look you can provide a sample project demonstrating the issue that shows Django is at fault.

Last edited 3 years ago by Carlton Gibson (previous) (diff)

comment:3 Changed 3 years ago by Kevin Golding

I did some more digging around based on what you said about the call to 'locale.getpreferredencoding()' and it turns it is environmental as you suggested.

The short answer is that when running from Apache the locale is not set to anything and seems to default to ascii. The author of mod_wsgi has written a pretty good explanation of what is going on and how to fix it here: (tl;dr run in daemon mode and set lang and locale in the WSGIDaemonProcess configuration)

I still don't understand why this problem doesn't occur with Python 2 and/or Django 2.1 or earlier.

comment:4 Changed 3 years ago by Mariusz Felisiak

Resolution: needsinfoduplicate

Duplicate of #30324.

Note: See TracTickets for help on using tickets.
Back to Top