Set encoding in Python 3 CGI scripts

前端 未结 7 1831
醉话见心
醉话见心 2020-12-03 03:07

When writing a Python 3.1 CGI script, I run into horrible UnicodeDecodeErrors. However, when running the script on the command line, everything works.

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 03:50

    Short answer: as detailed in mod_cgi + utf8 + Python3 produces no output, just add this in .htaccess:

    SetEnv PYTHONIOENCODING utf8
    

    along with:

    Options +ExecCGI
    AddHandler cgi-script .py
    

提交回复
热议问题