--版本python3
--模块:ftplib
一、使用ftplib上传文件的时候,遇到包含中文的文件名报错UnicodeEncodeError: 'latin-1' codec can't encode charactersin position 4-5: ordinal not in range(256)
更改ftplib.py里
encoding ='latin-1'
为
encoding ='utf-8'
ftplib.py文件一般在python安装目录的Lib文件夹下
二、文件名含中文,上传到FTP文件服务器文件名乱码 Ubuntu
按上面步骤修改完后程序可以正常运行,但是因为文件名包含中文,在我的Ubuntu服务器上显示一串问号。这可能是因为Ubuntu系统没有安装中文支持,具体步骤如下:
第一步,安装中文包:
sudo apt-get install language-pack-zh*
第二步,配置相关环境变量:
sudo vim /etc/environment
在文件中增加语言和编码的设置:
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"
我的配置文件显示如下: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"
第三步,重新设置本地配置:
sudo dpkg-reconfigure locales
其他linux版本的修改网上也都有,不在这里重复了
参考:
1、https://blog.csdn.net/zuihai/article/details/63685374
2、https://blog.csdn.net/chentengkui/article/details/77543498