运行我的Python App时出现以下错误。我在使用SQLite 3的SQL INSERT
查询中收到此错误。错误如下所示。
错误:
File "/opt/lampp/htdocs/rework/meeting/d60/mrb_Vulnerable/booking/views.py", line 72
SyntaxError: Non-ASCII character '\xe2' in file /opt/lampp/htdocs/rework/meeting/d60/mrb_Vulnerable/booking/views.py on line 72, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
我在下面的行中收到此错误。
conn = sqlite3.connect("db.sqlite3")
cursor = conn.cursor()
cursor.execute("insert into booking_meeting(room_name,from_date,to_date,no_seat,projector,video,created_date,location_name) values('{0}', '{1}','{2}', '{3}','{4}', '{5}','{6}', '{7}','{8}')".format(rname, from_date, to_date, seat, projector, video, now, location_name )
conn.commit()
我需要清除这个错误。
答案 0 :(得分:1)
在你的python代码的开头添加这一行
# -*- coding: utf-8 -*-
如果上述代码不起作用,请尝试使用
sys.setdefaultencoding('UTF8')