12 Mayıs 2012, CUMARTESİ
UnicodeDecodeError: 'konum 1' Kodek't decode byte ascıı 0xef
Bazı sorunlar UTF-8 için bir dize kodlamak için çabalıyorum. Birçok şey, string.encode('utf-8')
unicode(string)
kullanarak da dahil olmak üzere denedim ama hata alıyorum:
UnicodeDecodeError: 'ascii' Kodek konumu 1 byte 0xef çözebilir mi: range(128) sıra
Bu benim dize
(。・ω・。)ノ
Yanlış giden şeyin ne olduğunu anlamadım, bir fikriniz var mı?
Edit: sorun aynı dize baskı düzgün göstermiyor. Ayrıca, dönüştürmeye çalıştığımda bu hata:
Python 2.7.1 (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128)
CEVAP
12 Mayıs 2012, CUMARTESİ
Bu terminal kodlama UTF-8 için ayarlanmamış. İşte benim terminal
$ echo $LANG
en_GB.UTF-8
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
(。・ω・。)ノ
>>>
Benim terminal örnek olarak yukarıdaki ile çalışır, ama eğer LANG
ayar edersem o zaman işe yaramaz
$ unset LANG
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128)
>>>
Linux türevi için doktorlar bu değişikliği kalıcı yapmak için nasıl keşfetmek için başvurun.
Bunu Paylaş:
- 'ascıı' Kodek't decod...
Geçersiz devamı byte UnicodeDecodeErro...
UnicodeEncodeError: 'ascıı' ...
Nasıl HTML5 coğrafi konum Çalışır?...
Pencere.konum:href Pencere.() açık Jav...