---
title: "python终极解决UnicodeEncodeError"
author: "xushans"
date: "2016-02-26T16:31:29Z"
tags: []
categories: ["企业架构"]
slug: "python-unicodeencodeerror"
draft: false
lastmod: "2016-02-26T16:31:29Z"
id: 2279117
url: "https://xushans.iteye.com/blog/2279117"
---

python环境下没有设置defaultEncoding的场合，通常会报错UnicodeEncodeError。

我机器下的python安装在/usr/lib/python2.7
在该路径下新建sitecustomize.py


```python
import sys
sys.setdefaultencoding('utf-8')
```


ok了