Click 将中止进一步的执行,因为 Python 3 被配置为使用 ASCII 作为环境的编码 [英] Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment

查看:15
本文介绍了Click 将中止进一步的执行,因为 Python 3 被配置为使用 ASCII 作为环境的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Quokka Python/Flask CMS 下载到了 CentOS7 服务器.使用命令一切正常

I downloaded Quokka Python/Flask CMS to a CentOS7 server. Everything works fine with command

sudo python3 manage.py runserver --host 0.0.0.0 --port 80

然后我创建一个文件/etc/init.d/quokkacms.该文件包含以下代码

Then I create a file /etc/init.d/quokkacms. The file contains following code

start() {
        echo -n "Starting quokkacms: "
        python3 /var/www/quokka/manage.py runserver --host 0.0.0.0 --port 80
        touch /var/lock/subsys/quokkacms
        return 0
}
stop() {
        echo -n "Shutting down quokkacms: "
        rm -f /var/lock/subsys/quokkacms
        return 0
}
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)

        ;;
    restart)
        stop
        start
        ;;

    *)
        echo "Usage: quokkacms {start|stop|status|restart}"
        exit 1
        ;;
esac
exit $?

但运行 sudo service quokkacms start

RuntimeError: Click 将中止进一步的执行,因为 Python 3 是配置为使用 ASCII 作为环境的编码.要么切换到 Python 2 或参考 http://click.pocoo.org/python3/ 了解
缓解措施.

RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Either switch to Python 2 or consult http://click.pocoo.org/python3/ for
mitigation steps.

在我看来,它是 bash 脚本.我怎么会得到不同的结果?我也按照错误消息中链接中的说明进行操作,但仍然没有运气.

It seems to me that it is the bash script. How come I get different results? Also I followed instructions in the link in the error message but still had no luck.

[更新] 在发布此问题之前,我已经尝试过 Click 提供的解决方案.检查以下结果(我在 root 中运行):

[update] I had already tried the solution provided by Click before I posted this question. Check the results below (i run in root):

[root@webserver quokka]# python3
Python 3.4.3 (default, Jan 26 2016, 02:25:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> import codecs
>>> print(locale.getpreferredencoding())
UTF-8
>>> print(codecs.lookup(locale.getpreferredencoding()).name)
utf-8
>>> locale.getdefaultlocale()
('en_US', 'UTF-8')
>>> locale.CODESET
14
>>>

推荐答案

如果您尝试执行测试用例,您必须每次设置以下环境变量:

If you are trying to execute tests case you must set the following environment variables each time:

export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8

每次都这样做可以解决错误.

Doing this each time will resolve the error.

也可以在 IDE 运行配置中将其设置为

It may also be possible to set this in your IDE run configuration as

LC_ALL=en_US.UTF-8;LANG=en_US.UTF-8

例如,请参阅 PyCharm 2016 中的以下设置:

For example see the following setting in PyCharm 2016:

这篇关于Click 将中止进一步的执行,因为 Python 3 被配置为使用 ASCII 作为环境的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆