0

I am using Python 2.7 and pafy to download audio file from youtube

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

I get the following error:

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

Please Help! Thanks in advance.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Vadym
  • 136
  • 1
  • 2

1 Answers1

1

I have found the solution. The problem is solved by replacing one string in util.py file C:\Python27\Lib\site-packages\pafy\util.py I replaced that string in util.py:

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

by this one:

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

After that file successfully downloaded without any problems.

Vadym
  • 136
  • 1
  • 2