0

我正在使用 Python 2.7 和 pafy 从 youtube 下载音频文件

import pafy
video = pafy.new("https://www.youtube.com/watch?v=dcNlEn1LrrE")
print video.m4astreams
filename = video.m4astreams[0].download(quiet=False)

我收到以下错误:

Traceback (most recent call last):
File "E:\work\Python\2017\pafy\work_with_pafy.py", line 27, in <module>
filename = video.m4astreams[0].download(quiet=False)#.encode('utf-8')
File "c:\python27\lib\site-packages\pafy\backend_shared.py", line 586, in      download
filename = self.generate_filename(meta=meta, max_length=256-len('.temp'))
File "c:\python27\lib\site-packages\pafy\backend_shared.py", line 458, in generate_filename
return xenc(filename)
File "c:\python27\lib\site-packages\pafy\util.py", line 63, in xenc
return utf8_replace(stuff) if not_utf8_environment else stuff
File "c:\python27\lib\site-packages\pafy\util.py", line 57, in utf8_replace
txt = txt.encode(sse, "replace").decode(sse)
TypeError: encode() argument 1 must be string, not None

请帮忙!提前致谢。

4

1 回答 1

1

我找到了解决方案。通过替换 util.py 文件 C:\Python27\Lib\site-packages\pafy\util.py 中的一个字符串来解决问题我在 util.py 中替换了该字符串:

txt = txt.encode(sse, "replace").decode(sse)

通过这个:

txt = txt.encode('utf-8')

该文件成功下载后没有任何问题。

于 2017-03-11T11:59:16.373 回答