码迷,mamicode.com
首页 > 编程语言 > 详细

python2 使用openpyxl 报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 20: ordinal not in range(128) 解决方法

时间:2018-04-27 13:36:45      阅读:1059      评论:0      收藏:0      [点我收藏+]

标签:charm   解决   代码   file   recent   write   types   ascii   try   

# -*- coding: utf-8 -*-
#! /usr/bin/env python
# author: xiao~~

import openpyxl
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8‘)

wb2=openpyxl.Workbook()

wb2.save(‘test1.xlsx‘)
print(‘新建成功‘)

  附上剪短的代码

报错信息

Traceback (most recent call last):
File "F:\PyCharm 5.0.4\helpers\pydev\pydevd.py", line 2411, in <module>
globals = debugger.run(setup[‘file‘], None, None, is_module)
File "F:\PyCharm 5.0.4\helpers\pydev\pydevd.py", line 1802, in run
launch(file, globals, locals) # execute the script
File "D:/test/yf_test/conf/test1.py", line 5, in <module>
import openpyxl
File "F:\Python27\lib\site-packages\openpyxl\__init__.py", line 29, in <module>
from openpyxl.workbook import Workbook
File "F:\Python27\lib\site-packages\openpyxl\workbook\__init__.py", line 5, in <module>
from .workbook import Workbook
File "F:\Python27\lib\site-packages\openpyxl\workbook\workbook.py", line 17, in <module>
from openpyxl.writer.excel import save_workbook, save_dump
File "F:\Python27\lib\site-packages\openpyxl\writer\excel.py", line 31, in <module>
from openpyxl.packaging.manifest import Manifest
File "F:\Python27\lib\site-packages\openpyxl\packaging\manifest.py", line 41, in <module>
mimetypes.init()
File "F:\Python27\lib\mimetypes.py", line 358, in init
db.read_windows_registry()
File "F:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
for subkeyname in enum_types(hkcr):
File "F:\Python27\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xd7 in position 20: ordinal not in range(128)

 

将F:\Python27\Lib\mimetypes.py这个文档下屏蔽就可以

技术分享图片

 

我已验证可以成功解决

 

python2 使用openpyxl 报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 20: ordinal not in range(128) 解决方法

标签:charm   解决   代码   file   recent   write   types   ascii   try   

原文地址:https://www.cnblogs.com/xiaoxiao-niao/p/8961005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!