shutil.make_archive抛出UnicodeEncodeError

时间:2018-03-15 14:47:08

标签: python python-3.x heroku

我试图通过python的shutil.make_archive压缩wordpress网站(很多文件)的一些备份,但我收到了这个错误:

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.5/zipfile.py", line 432, in _encodeFilenameFlags
    return self.filename.encode('ascii'), self.flag_bits
UnicodeEncodeError: 'ascii' codec can't encode character '\udcc3' in position 61: ordinal not in range(128)

我正在使用python 3.6.1并在heroku上运行它。

以下是在某些情况下有效的实际代码,在某些情况下它不会:

zipped = shutil.make_archive( zip_file_name, 'zip', self.folder_path, self.time )

我希望有人可以帮我找到解决这个问题的方法。

谢谢!

1 个答案:

答案 0 :(得分:0)

看起来zip_file_name有非英语字符。

尝试:

zipped = shutil.make_archive( zip_file_name.decode('utf8','surrogateescape'), 'zip', self.folder_path, self.time )