python中文报错

当输出中文时,错误信息如下:

SyntaxError at /time/

Non-ASCII character ‘\xe7‘ in file e:\pythonCode\firstsite\firstsite\view.py on line 15, but no encoding declared; see http://www.python.org/peps/pep-0263.html for 

经百度,必须在代码前面加注这两句

#coding=gbk

#coding=utf-8

才解决

from django.http import HttpResponse
#coding=gbk

#coding=utf-8
import datetime

时间: 2024-08-29 08:17:19

python中文报错的相关文章

Python 中文报错 SyntaxError: Non-ASCII character解决办法

只需要在最顶部的位置加上 1 #-*- coding:utf-8 -*- 就行了. 如果还是没有好,打开设置并搜索file encoding并作如图修改便好.

Pycharm中不支持中文编码的解决方案。Pycharm中文报错。 Pycharm出现的部分快捷键无效及解决办法

Pycharm中不支持中文编码的解决方案.Pycharm中文报错. 1. 打开Pycharm ---->  File ----> Default setting ------> Editor -------> File Encodings ,如下图,设置成UTF-8, 然后应用 2.  点击[File]---[Setting]---[Editor]---[File and Code Templates],点击右边的[python script],在编辑框中输入: #-*-codin

客户端cmd打开mysql,执行插入中文报错或插入中文乱码解决方案

最近在制作一个安装包,需要安装的时候执行mysql脚本儿,做了一个批处理,但是发现总是执行到 插入中文的时候报错,或者插入中文是乱码. 网上查了好多资料,说是把编码改成GBK什么的,终究还是不成功. 最后经过多次测试,现把解决方案分享给大家. 第一步:打开mysql中的配置文件,my.ini,看一看配置文件中 [mysql] default-character-set=utf8 [mysqld] character-set-server=utf8 看是不是这样配置的.因为utf8 是国际通用的,

mybatis中xml的sql之test中文报错

在mybatis中sql,test中文报错( java.lang.NumberFormatException 这句话明确告诉了我们是数字格式异常).需加.tostring(). <if test="bookName == '毛选集'.tostring() "> and b.book_Name like #{bookName} </if>

Python递归报错:RuntimeError: maximum recursion depth exceeded in comparison

Python中默认的最大递归深度是989,当尝试递归第990时便出现递归深度超限的错误: RuntimeError: maximum recursion depth exceeded in comparison 简单方法是使用阶乘重现: 1 #! /usr/bin/env Python 2 3 def factorial(n): 4 5 if n == 0 or n == 1: 6 7 return 1 8 9 else: 10 11 return(n * factorial(n - 1)) >

python 编码报错问题 &#39;ascii&#39; codec can&#39;t encode characters 解决方法

python在安装时,默认的编码是ascii, 当程序中出现非ascii编码时,python的处理常常会报这样的错 'ascii' codec can't encode characters python没办法处理非ascii编码的, 此时需要自己设置将python的默认编码,一般设置为utf8的编码格式. 查看python的默认编码 print sys.getdefaultencoding() 解决方法一(已通过验证,顺带也解决了我之前字符前一直加u的问题) 在python安装目录下,进入\P

iOS开发-url包含中文报错解决办法

经常, 我们用通过这样的方法调用API. NSString* urlString = [NSString stringWithFormat:@"http://api.douban.com/v2/movie/search?q=%@", content]; NSURL *url = [NSURL URLWithString:urlString]; testRequest = [ASIHTTPRequest requestWithURL:url]; [testRequest setDeleg

安装python模块报错 error: command &#39;gcc&#39; failed with exit status 1

最近在安装paramiko模块的时候,总是报错:error: command 'gcc' failed with exit status 1,一开始比较挠头.找了蛮多资料,说的大多都是说缺少Python-devel 包,然而并不是! 最后蛮费劲的找到了一遍短小但就是正确的博文:http://blog.csdn.net/fenglifeng1987/article/details/38057193 —————————————————————— 解决方法: 安装:yum install gcc li

django admin 中文报错incorrect string value解决方案

对于错误" Incorrect string value: '\xE6\xA2\xB5\xE8\x92\x82...'for column 'object_repr' at row 1 解决方法是设置django_admin_log表的object_repr一项使用utf8_unicode_ci: 对于错误"  Incorrect string value: '\xE6\xA2\xB5\xE8\x92\x82...'for column 'change_message' at row