Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No encoding declared

I keep getting this error:

 SyntaxError: Non-ASCII character '\xe4' in file /var/www/mooimom_django/mooimom_tw/models.py on line 716, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

because of:

subdistrict_destination_text    = models.CharField(verbose_name=pgettext_lazy('taiwan-models Shopping_Cart', "Subdistrict Destination Text"), max_length=255, default='100 中正區')

How to solve this problem? thanks

like image 981
RaR Avatar asked May 30 '17 04:05

RaR


People also ask

How do I fix encoding in Python?

The best way to attack the problem, as with many things in Python, is to be explicit. That means that every string that your code handles needs to be clearly treated as either Unicode or a byte sequence. The most systematic way to accomplish this is to make your code into a Unicode-only clean room.

What is Python's default encoding?

UTF-8 is one of the most commonly used encodings, and Python often defaults to using it. UTF stands for “Unicode Transformation Format”, and the '8' means that 8-bit values are used in the encoding. (There are also UTF-16 and UTF-32 encodings, but they are less frequently used than UTF-8.)


1 Answers

add this to top of your file:

# -*- coding: utf-8 -*-
like image 152
Mani Shirvani Avatar answered Oct 04 '22 04:10

Mani Shirvani