1

I've deployed a Python web application (uses Pyramid) in Apache (httpd) using mod_wsgi.

After starting the Apache service the error below (from Apache log) occurs when we make a http request to the web application...

[Mon Feb 06 16:38:55.980119 2017] [wsgi:error] [pid 16031] [remote 172.16.13.1:204] mod_wsgi (pid=16031): Target WSGI script '/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi' cannot be loaded as Python module.
[Mon Feb 06 16:38:55.980205 2017] [wsgi:error] [pid 16031] [remote 172.16.13.1:204] mod_wsgi (pid=16031): Exception occurred processing WSGI script '/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi'.
Traceback (most recent call last):
  File "/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi", line 1, in <module>
    from pyramid.paster import get_app
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/paster.py", line 10, in <module>
    from pyramid.scripting import prepare
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/scripting.py", line 1, in <module>
    from pyramid.config import global_registries
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/config/__init__.py", line 30, in <module>
    from pyramid.exceptions import (
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/exceptions.py", line 1, in <module>
    from pyramid.httpexceptions import (
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/httpexceptions.py", line 138, in <module>
    from pyramid.response import Response
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/response.py", line 23, in <module>
    init_mimetypes(mimetypes)
  File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/response.py", line 16, in init_mimetypes
    mimetypes.init()
  File "/usr/local/lb/py32/lib/python3.2/mimetypes.py", line 351, in init
    db.read(file)
  File "/usr/local/lb/py32/lib/python3.2/mimetypes.py", line 203, in read
    self.readfp(fp, strict)
  File "/usr/local/lb/py32/lib/python3.2/mimetypes.py", line 214, in readfp
    line = fp.readline()
  File "/usr/local/lb/py32/lib/python3.2/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2727: ordinal not in range(128)

That web python application works perfectly in all these distros: Ubuntu 14.04, Debian 8, RedHat 6, CentOS 6, Suse 12 and openSUSE 13, but not in CentOS 7... =[

We are using "Python 3.2.2," "mod_wsgi 4.3.2" and "Apache 2.4.6" in a "CentOS 7". The web application was built on top of Pyramid Web Framework (http://docs.pylonsproject.org/projects/pyramid/en/latest/).

This is a fairly common error! So far I have not found a way to get more information about this error.

We have tried everything to solve this problem and we simply do not know why it occurs... =[

Please help me!

Eduardo Lucio
  • 269
  • 4
  • 14

1 Answers1

2

The problem occurs because the /etc/mime.types file of CentOS 7 has the character "³" (line "application/vnd.geocube+xml g3 g³") which is invalid for ascii (not extended).

To figure this out I had to make some modifications to my Python 3.2.2 and reload my application.

The solution is remove the "³" character or any other invalid (ascii) character!

@MichaelHampton

Thanks!

Eduardo Lucio
  • 269
  • 4
  • 14
  • Pretty sure this is happening because you don't have mod_wsgi set up with the correct encoding, so it's using ascii instead of utf-8. Your workaround may work OK, but you'll wind up with problems [like mine](https://stackoverflow.com/questions/64564924/how-to-set-preferred-encoding-in-wsgi-to-utf-8#64564924), I think. – mlissner Oct 28 '20 at 03:25