无法使用pafy下载文件

时间:2017-03-11 01:15:01

标签: python pafy

我正在使用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

请帮忙! 提前谢谢。

1 个答案:

答案 0 :(得分: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')

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