UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 1: surrogates not allowed根本解决方法
下午开发新改的代码在print路径时出现上述问题,如下:
Traceback (most recent call last):
File "./update.py", line 606, in <module>
replace_exec_script()
File "./update.py", line 550, in replace_exec_script
print(file_path.encode('gbk').decode('utf-8'))
UnicodeEncodeError: 'gbk' codec can't encode character '\udcd6' in position 49: illegal multibyte sequence
网上搜了半天没找到解决方案。唯一解释到位的就是https://blog.csdn.net/lilongsy/article/details/80724799,其他都是不对号瞎扯,路径中有中文是个明确的需求,不是伪需求。
最后琢磨着这个\udcd6,以及“默认情况下,Python假定所有文件名都已经根据 sys.getfilesystemencoding() 的值编码过了。 但是,有一些文件系统并没有强制要求这样做,因此允许创建文件名没有正确编码的文件。 这种情况不太常见,但是总会有些用户冒险这样做或者是无意之中这样做了( 可能是在一个有缺陷的代码中给 open() 函数传递了一个不合规范的文件名)。”,猜测这不是python的锅,估计linux下显示就是乱码的,果不其然,如下:
[root@oel-12c 201809]# find ./app/20180108Build/scripts/ -name "*.sql"
./app/20180108Build/scripts/conf/000005-????/TA000005_????1.sql
./app/20180108Build/scripts/conf/bo-????/12.sql
将其该文中文后,问题就解决了。那这个????文件名是如何生成的呢?原来是通过xftp上传的,上传时没有指定连接使用UTF-8编码,所以就乱码了。勾上UTF-8编码,问题解决了。
UnicodeEncodeError: 'utf-8' codec can't encode character '\udce4' in position 1: surrogates not allowed根本解决方法的更多相关文章
- 'gbk' codec can't encode character '\xa5' in position 4546: illegal multibyte sequence错误解决
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030') 原文 http://blog.csdn.net/jim7424 ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 1987: illegal multibyte sequence
在爬取 url = "http://stats.meizhou.gov.cn/show/index/1543/1689" 时出现了问题: UnicodeEncodeError: ' ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 30633: illegal multibyte sequence
import urllib.request def load_baidu(): url = "https://www.baidu.com/" header = {"Use ...
- Python Solve UnicodeEncodeError 'gbk' / 'ascii' / 'utf8' codec can't encode character '\x??' in position ? 解决有关Python编码的错误
在Python中,处理中文字符一直是很令人头痛的问题,一言不合就乱码,而且引起乱码的原因也不尽相同,有时候是python本身默认的编码器设置的不对,有时候是使用的IDE的解码器不对,还有的时候是终端t ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...
- UnicodeEncodeError: 'gbk' codec can't encode character '\u25aa' in position 15: illegal multibyte sequence
UnicodeEncodeError: 'gbk' codec can't encode character '\u25aa' in position 15: illegal multibyte se ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转)
原文地址:https://www.cnblogs.com/feng18/p/5646925.html 从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'g ...
- python 写入日志的问题 UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 0: illegal multibyte sequence
最近,使用python的logging模块,因为这个写入日志写完后就没有管它.在存储日志信息的时候,一直提示: UnicodeEncodeError: 'gbk' codec can't encode ...
随机推荐
- [LeetCode] 405. Convert a Number to Hexadecimal_Easy tag: Bit Manipulation
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s compl ...
- @Value("#{}") 和 @Value("{}")
1 @Value("#{}") SpEL表达式 @Value("#{}") 表示SpEl表达式通常用来获取bean的属性,或者调用bean的某个方法.当然还 ...
- calibur处理ROSETTA输出的多个结构文件,clustering
下载网址:https://sourceforge.net/projects/calibur/ 安装: $ tar zxvf calibur.tar.gz $ cd calibur $ make 安装完 ...
- iOS UI进阶-4.0 地图与定位
在移动互联网时代,移动app能解决用户的很多生活琐事,比如 导航:去任意陌生的地方 周边:找餐馆.找酒店.找银行.找电影院 在上述应用中,都用到了地图和定位功能,在iOS开发中,要想加入这2大功能 ...
- unity3d生命周期
- spring注解式开发之视图解析器
http://localhost:8089/springmvc-04-viewResovler/springmvc/hello
- 理解tcp顺序释放操作和tcp的半关闭
Shutdown的调用 在关闭socket的时候,可以有两种方式closesocket和shutdown,这两个函数的区别在什么地方呢? #include <sys/socket. ...
- selenium获取文本
# 标题list_title = driver.find_elements_by_xpath('//*[@id="share-content"]/div/div[1]/ul/li/ ...
- rpm方式安装MySQL5.1.73
1.安装MySQL server 首先下载好mysql的rpm安装包 使用rpm命令安装: rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm 命令解释:i ...
- 《大话设计模式》c++实现 之工厂模式
工厂模式 工厂模式(Factory Pattern)是 Java 中最常用的设计模式之一.这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式. 在工厂模式中,我们在创建对象时不会对客户端 ...