Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: Non-ASCII character but no encoding declared [duplicate]

I am suppose to change some of these characters in English to Chinese in this setting.py file but then error happened.

I know that it's saying because no encoding is declared in the error message but I have been reading a few posts and still have no idea how / where I can make it happen.

in my setting.py I have something like this

OSCAR_DASHBOARD_NAVIGATION = [
{
    'label': _('dashboard'),
    'icon': 'icon-th-list',
    'url_name': 'dashboard:index',
},

but need to change the navigation to Chinese so ended up looking like this

OSCAR_DASHBOARD_NAVIGATION = [
{
    'label': _('仪表板'),
    'icon': 'icon-th-list',
    'url_name': 'dashboard:index',
},

Edit, I already read the post which thought might be duplicated and tried what's in that post and instead of getting errors, I get a no show in my page but regarding to Pedru's answer. It works like a charm now.

like image 326
Dora Avatar asked Apr 04 '16 09:04

Dora


People also ask

How do you use non-ascii characters in Python?

In order to use non-ASCII characters, Python requires explicit encoding and decoding of strings into Unicode. In IBM® SPSS® Modeler, Python scripts are assumed to be encoded in UTF-8, which is a standard Unicode encoding that supports non-ASCII characters.

What is a non-ASCII character?

Non-ASCII characters are those that are not encoded in ASCII, such as Unicode, EBCDIC, etc. ASCII is limited to 128 characters and was initially developed for the English language.

What is xe2 character?

\xe2 is the '-' character, it appears in some copy and paste it uses a different equal looking '-' that causes encoding errors. Replace the '-'(from copy paste) with the correct '-' (from you keyboard button).


1 Answers

Try adding

# -*- coding: utf-8 -*-

at the beginning of the file, make sure your file is really encoded in utf-8

like image 193
Pedru Avatar answered Nov 14 '22 21:11

Pedru