惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
Jina AI
Jina AI
雷峰网
雷峰网
月光博客
月光博客
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
美团技术团队
C
CXSECURITY Database RSS Feed - CXSecurity.com
小众软件
小众软件
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
A
Arctic Wolf
Latest news
Latest news
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
F
Fortinet All Blogs
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
Help Net Security
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
V
Visual Studio Blog
P
Proofpoint News Feed
博客园 - 【当耐特】
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
H
Help Net Security
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog

博客园 - jingleguo

[zz]软件测试专业术语 word分栏时脚注强制分页问题解决 安装JDK和TOMCAT并配置环境变量的过程 - jingleguo - 博客园 Thinkpad鼠标在Chrome中无法使用滚轮 [zz]第五套人民币发行冠号 SourceForge镜像 How Can You Buy or Sell The Sky?[zz] china-pub返回的错误网页 - jingleguo - 博客园 X61 T61 休眠后自动重启与耗电问题 自题 'You've got to find what you love,' Jobs says 使用VC向Windows发送消息代码示例 百度千万别做邮箱 察传 赋得自君之出矣 用逻辑来骗MM和在论坛上骗钱 Google 的午餐 Java使用Scream流读入并输出文件示例 集句
Python设置默认语言编码
jingleguo · 2008-06-02 · via 博客园 - jingleguo

当python中间处理非ASCII编码时,经常会出现如下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128)
0x??是超出128的数字,python在默认的情况下认为语言的编码是ascii编码,所以无法处理其他编码,需要设置python的默认编码为所需要的编码。
一个解决的方案是在代码中添加:

import sys

reload(sys)
sys.setdefaultencoding('gb2312')

另一个方案是在python的Lib\site-packages文件夹下新建一个sitecustomize.py
文件(sitecustomize.py is a special script; Python will try to import it on startup, so any code in it will be run automatically.),输入:

import sys
sys.setdefaultencoding('gb2312')

这样就能够自动的设置编码了。
ps:
1. utf8的编码是:utf-8

2. 测试已经成功的方法:
>>> import sys
>>> sys.getdefaultencoding()