La interfaz con los caracteres Unicode es el problema cuando corres Python desde la consola de Windows.
Las versiones de Python anteriores a la 3.6 usan el console character encoding (chcp) de la consola de Windows (The codepage is often 8-bit encoding such as cp437 that can represent only ~0x100 characters from ~1M Unicode characters), sin embargo la consola si soporta los caracteres Unicode siempre y cuando una font adecuada sea configurada.
Puedes instalar el paquete win-unicode-console para que Python utilice la Unicode API de Windows:
Código: python
Antes de utilizar win-unicode-console:
Código: python
Código: text
Utilizando win-unicode-console:
Código: python
Código: text
fuente:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Saludos
Las versiones de Python anteriores a la 3.6 usan el console character encoding (chcp) de la consola de Windows (The codepage is often 8-bit encoding such as cp437 that can represent only ~0x100 characters from ~1M Unicode characters), sin embargo la consola si soporta los caracteres Unicode siempre y cuando una font adecuada sea configurada.
Puedes instalar el paquete win-unicode-console para que Python utilice la Unicode API de Windows:
pip install win-unicode-console
Antes de utilizar win-unicode-console:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from pytube import YouTube
# not necessary, just for demo purposes.
from pprint import pprint
yt = YouTube("https://www.youtube.com/watch?v=Qp2H-9iNTvE")
yt.get_videos()
print(yt.filename.encode('utf_8', 'replace'))
print(yt.filename)
print(yt.filename.decode('utf_8', 'replace'))
RESULTADO=
Hardcore 2017 ΓÖª Dominator Festival 2017 ΓÖª Warm-Up Mix ΓÖª Festival Video ΓÖª Air Force Festival 2017
Traceback (most recent call last):
File "prueba.py", line 14, in <module>
print(yt.filename)
File "C:\Python27\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2666' in position 14: character maps to <undefined>
Utilizando win-unicode-console:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import win_unicode_console
win_unicode_console.enable()
from pytube import YouTube
# not necessary, just for demo purposes.
from pprint import pprint
yt = YouTube("https://www.youtube.com/watch?v=Qp2H-9iNTvE")
yt.get_videos()
print(yt.filename.encode('utf_8', 'replace'))
print(yt.filename)
print(yt.filename.decode('utf_8', 'replace'))
RESULTADO=
Hardcore 2017 ♦ Dominator Festival 2017 ♦ Warm-Up Mix ♦ Festival Video ♦ Air Force Festival 2017
Hardcore 2017 ♦ Dominator Festival 2017 ♦ Warm-Up Mix ♦ Festival Video ♦ Air Force Festival 2017
Hardcore 2017 ♦ Dominator Festival 2017 ♦ Warm-Up Mix ♦ Festival Video ♦ Air Force Festival 2017
fuente:
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Saludos

