Click cancels further execution because Python 3 has been configured to use ASCII as the encoding for the environment

I uploaded Quokka Python / Flask CMS to a CentOS7 server. Everything works great with the team

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

Then I create the file /etc/init.d/quokkacms. The file contains the 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 $? 

But I get an error when starting sudo service quokkacms start

RuntimeError: Click cancels further execution because Python 3 has been configured to use ASCII as the encoding for the environment. Any switch to Python 2 or refer to http://click.pocoo.org/python3/ for
mitigation steps.

It seems to me that this is a bash script. Why do I have different results? I also followed the instructions in the link in the error message, but still no luck.

[update] I already tried the solution provided by the click before I posted this question. Check the results below (I ran 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 >>> 
+20
source share
3 answers

If you are trying to run a test suite, you must set the following environment variables each time:

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

By doing this each time, you will correct the error.

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

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

For example, see the following option in PyCharm 2016:

+35
source

Add more to existing solutions:

If you see something like this error in Python 3:

 Traceback (most recent call last): ... 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. 

You are dealing with an environment in which Python 3 considers you to be limited to ASCII data. The solution to these problems varies depending on which locale your computer is running on.

For example, if you have a German Linux machine, you can solve this problem by exporting the locale to de_DE.utf-8:

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

If you are working on an American computer, en_US.utf-8 is the selected encoding. On some newer Linux systems, you can also use C.UTF-8 as a locale:

 export LC_ALL=C.UTF-8 export LANG=C.UTF-8 

Adapted from Python 3 Surrogate Handling

+1
source

At the top of your Python script, try putting

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

All Articles