我得到的錯誤,如另一個Python的unicode錯誤
UnicodeEncodeError('ascii', u'\x01\xff \xfeJ a z z', 1, 2, 'ordinal not in range(128)'
我也越來越序列,如
u'\x17\x01\xff \xfeA r t B l a k e y'
我承認\ X01 \ XFF \ XFE作爲一個BOM,但如何我是否將這些轉化爲明顯的輸出(爵士樂和藝術Blakey)?
這些來自讀取音樂文件標籤的程序。
我已經嘗試過各種編碼,例如s.encode('utf8')和各種解碼,然後是編碼,但沒有成功。
按照要求:
from hsaudiotag import auto
inf = 'test.mp3'
song = auto.File(inf)
print song.album, song.artist, song.title, song.genre
> Traceback (most recent call last): File "audio2.py", line 4, in
> <module>
> print song.album, song.artist, song.title, song.genre File "C:\program files\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'\xfe' in
> position 4 : character maps to <undefined>
如果我改變print語句
with open('x', 'wb') as f:
f.write(song.genre)
我得到
Traceback (most recent call last):
File "audio2.py", line 6, in <module>
f.write(song.genre)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 1:
ordinal not in range(128)
從獲取原始字節輸入到出現此錯誤的位置顯示代碼可能會有所幫助。並顯示整個堆棧跟蹤。 – Marcin
這個unicode是運行一個名爲hsaudiotag的音樂文件標籤讀取程序的直接輸出。該錯誤是由打印或寫入語句生成的。我也得到UnicodeEncodeError:'ascii'編解碼器不能在位置1編碼字符u'\ xff': 序號不在範圍內(128) – foosion
請按照我詢問過的內容來做。我不在乎這是從哪裏輸出的。 – Marcin